fix pprof.

This commit is contained in:
Miroslav Šedivý
2023-11-25 15:37:08 +01:00
parent cdd0e4fad2
commit ffeef5e887
2 changed files with 6 additions and 39 deletions
-33
View File
@@ -1,33 +0,0 @@
package server
import (
"net/http"
"net/http/pprof"
"github.com/go-chi/chi/v5"
)
const pprofPath = "/debug/pprof/"
func withPProf(router *chi.Mux) {
router.Route(pprofPath, func(r chi.Router) {
r.Get("/", pprof.Index)
r.Get("/{action}", func(w http.ResponseWriter, r *http.Request) {
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)
}
})
})
}
+6 -6
View File
@@ -58,12 +58,6 @@ func New(ApiManager types.ApiManager, roomConfig *config.Room, config *config.Se
})) }))
} }
// mount pprof endpoint
if config.PProf {
withPProf(router)
logger.Info().Msgf("with pprof endpoint at %s", pprofPath)
}
// //
// admin page // admin page
// //
@@ -240,6 +234,12 @@ func New(ApiManager types.ApiManager, roomConfig *config.Room, config *config.Se
}) })
} }
// mount pprof endpoint
if config.PProf {
router.Mount("/debug", middleware.Profiler())
logger.Info().Msgf("with pprof endpoint")
}
// handle all remaining paths with proxy // handle all remaining paths with proxy
router.Handle("/*", proxyHandler) router.Handle("/*", proxyHandler)