Change to our own middleware for pprof
Cette révision appartient à :
Parent
2c0293470a
révision
7e22828cb3
|
@ -25,3 +25,10 @@ func modMiddleware() gin.HandlerFunc {
|
|||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func pprofHandler(h http.HandlerFunc) gin.HandlerFunc {
|
||||
handler := http.HandlerFunc(h)
|
||||
return func(c *gin.Context) {
|
||||
handler.ServeHTTP(c.Writer, c.Request)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package controllers
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/utils/captcha"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/justinas/nosurf"
|
||||
|
@ -142,6 +144,14 @@ func init() {
|
|||
Router.GET("/settings", SeePublicSettingsHandler)
|
||||
Router.POST("/settings", ChangePublicSettingsHandler)
|
||||
|
||||
// Adding pprof support
|
||||
Router.GET("/debug/pprof/block", pprofHandler(pprof.Index))
|
||||
Router.GET("/debug/pprof/heap", pprofHandler(pprof.Index))
|
||||
Router.GET("/debug/pprof/profile", pprofHandler(pprof.Profile))
|
||||
Router.POST("/debug/pprof/symbol", pprofHandler(pprof.Symbol))
|
||||
Router.GET("/debug/pprof/symbol", pprofHandler(pprof.Symbol))
|
||||
Router.GET("/debug/pprof/trace", pprofHandler(pprof.Trace))
|
||||
|
||||
CSRFRouter = nosurf.New(Router)
|
||||
CSRFRouter.ExemptRegexp("/api(?:/.+)*")
|
||||
CSRFRouter.ExemptRegexp("/mod(?:/.+)*")
|
||||
|
@ -154,4 +164,5 @@ func init() {
|
|||
Path: "/",
|
||||
MaxAge: nosurf.MaxAge,
|
||||
})
|
||||
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -9,8 +9,6 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/controllers"
|
||||
"github.com/NyaaPantsu/nyaa/models"
|
||||
|
@ -30,6 +28,7 @@ func RunServer(conf *config.Config) {
|
|||
// TODO Use config from cli
|
||||
os.Mkdir(controllers.GPGPublicKeyPath, 0700)
|
||||
|
||||
|
||||
http.Handle("/", controllers.CSRFRouter)
|
||||
|
||||
// Set up server,
|
||||
|
|
Référencer dans un nouveau ticket