mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add pprof.
This commit is contained in:
36
internal/http/debug.go
Normal file
36
internal/http/debug.go
Normal file
@ -0,0 +1,36 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func pprofHandler(r types.Router) {
|
||||
r.Get("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) error {
|
||||
pprof.Index(w, r)
|
||||
return nil
|
||||
})
|
||||
|
||||
r.Get("/debug/pprof/{action}", func(w http.ResponseWriter, r *http.Request) error {
|
||||
action := chi.URLParam(r, "action")
|
||||
|
||||
switch action {
|
||||
case "cmdline":
|
||||
pprof.Cmdline(w, r)
|
||||
case "profile":
|
||||
pprof.Profile(w, r)
|
||||
case "symbol":
|
||||
pprof.Symbol(w, r)
|
||||
case "trace":
|
||||
pprof.Trace(w, r)
|
||||
default:
|
||||
pprof.Handler(action).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
@ -57,6 +57,10 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
|
||||
})
|
||||
}
|
||||
|
||||
if config.PProf {
|
||||
pprofHandler(router)
|
||||
}
|
||||
|
||||
return &HttpManagerCtx{
|
||||
logger: logger,
|
||||
config: config,
|
||||
|
Reference in New Issue
Block a user