From ffeef5e8872f556b090270f54efaeb6d2e9a1bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 25 Nov 2023 15:37:08 +0100 Subject: [PATCH] fix pprof. --- internal/server/debug.go | 33 --------------------------------- internal/server/manager.go | 12 ++++++------ 2 files changed, 6 insertions(+), 39 deletions(-) delete mode 100644 internal/server/debug.go diff --git a/internal/server/debug.go b/internal/server/debug.go deleted file mode 100644 index 1ff18c1..0000000 --- a/internal/server/debug.go +++ /dev/null @@ -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) - } - }) - }) -} diff --git a/internal/server/manager.go b/internal/server/manager.go index 312453e..d5ca21f 100644 --- a/internal/server/manager.go +++ b/internal/server/manager.go @@ -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 // @@ -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 router.Handle("/*", proxyHandler)