Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Change to our own middleware for pprof

Cette révision appartient à :
akuma06 2017-07-05 14:40:05 +02:00
Parent 2c0293470a
révision 7e22828cb3
3 fichiers modifiés avec 19 ajouts et 2 suppressions

Voir le fichier

@ -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)
}
}

Voir le fichier

@ -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,
})
}

Voir le fichier

@ -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,