mirror of
https://github.com/adnanh/webhook.git
synced 2025-06-28 07:18:31 +00:00
* Update go-chi dependency to v5 * Update gofrs/uuid dependency to v5 * Update gorilla/mux dependency to v1.8.1 * Update go-humanize dependency to v1.0.1 * Update mxj dependency to v2.7.0 * Update fsnotify dependency to v1.7.0 * Update Go versions in GH build workflow * Update gopkg.in/yaml.v2 indirect dependency to v2.4.0 * Bump GH actions
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package middleware
|
|
|
|
import (
|
|
"expvar"
|
|
"net/http"
|
|
"net/http/pprof"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// Profiler is a convenient subrouter used for mounting net/http/pprof. ie.
|
|
//
|
|
// func MyService() http.Handler {
|
|
// r := chi.NewRouter()
|
|
// // ..middlewares
|
|
// r.Mount("/debug", middleware.Profiler())
|
|
// // ..routes
|
|
// return r
|
|
// }
|
|
func Profiler() http.Handler {
|
|
r := chi.NewRouter()
|
|
r.Use(NoCache)
|
|
|
|
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, r.RequestURI+"/pprof/", http.StatusMovedPermanently)
|
|
})
|
|
r.HandleFunc("/pprof", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Redirect(w, r, r.RequestURI+"/", http.StatusMovedPermanently)
|
|
})
|
|
|
|
r.HandleFunc("/pprof/*", pprof.Index)
|
|
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
|
|
r.HandleFunc("/pprof/profile", pprof.Profile)
|
|
r.HandleFunc("/pprof/symbol", pprof.Symbol)
|
|
r.HandleFunc("/pprof/trace", pprof.Trace)
|
|
r.Handle("/vars", expvar.Handler())
|
|
|
|
r.Handle("/pprof/goroutine", pprof.Handler("goroutine"))
|
|
r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate"))
|
|
r.Handle("/pprof/mutex", pprof.Handler("mutex"))
|
|
r.Handle("/pprof/heap", pprof.Handler("heap"))
|
|
r.Handle("/pprof/block", pprof.Handler("block"))
|
|
r.Handle("/pprof/allocs", pprof.Handler("allocs"))
|
|
|
|
return r
|
|
}
|