Add Profiler middleware

This commit is contained in:
Anton Zadvorny 2023-12-25 04:06:48 +03:00
parent 5eabae8e40
commit a5f83606cd
1 changed files with 29 additions and 0 deletions

29
profiler.go Normal file
View File

@ -0,0 +1,29 @@
package middleware
import (
"expvar"
"net/http"
"net/http/pprof"
)
// Profiler is a convenient subrouter used for mounting net/http/pprof
func Profiler() http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/pprof/", pprof.Index)
mux.HandleFunc("/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/pprof/profile", pprof.Profile)
mux.HandleFunc("/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/pprof/trace", pprof.Trace)
mux.Handle("/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/pprof/threadcreate", pprof.Handler("threadcreate"))
mux.Handle("/pprof/mutex", pprof.Handler("mutex"))
mux.Handle("/pprof/heap", pprof.Handler("heap"))
mux.Handle("/pprof/block", pprof.Handler("block"))
mux.Handle("/pprof/allocs", pprof.Handler("allocs"))
mux.Handle("/vars", expvar.Handler())
return Wrap(mux, NoCache)
}