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 }
()
| 21 | // return r |
| 22 | // } |
| 23 | func Profiler() http.Handler { |
| 24 | r := chi.NewRouter() |
| 25 | r.Use(NoCache) |
| 26 | |
| 27 | r.Get("/", func(w http.ResponseWriter, r *http.Request) { |
| 28 | http.Redirect(w, r, r.RequestURI+"/pprof/", http.StatusMovedPermanently) |
| 29 | }) |
| 30 | r.HandleFunc("/pprof", func(w http.ResponseWriter, r *http.Request) { |
| 31 | http.Redirect(w, r, r.RequestURI+"/", http.StatusMovedPermanently) |
| 32 | }) |
| 33 | |
| 34 | r.HandleFunc("/pprof/*", pprof.Index) |
| 35 | r.HandleFunc("/pprof/cmdline", pprof.Cmdline) |
| 36 | r.HandleFunc("/pprof/profile", pprof.Profile) |
| 37 | r.HandleFunc("/pprof/symbol", pprof.Symbol) |
| 38 | r.HandleFunc("/pprof/trace", pprof.Trace) |
| 39 | r.Handle("/vars", expvar.Handler()) |
| 40 | |
| 41 | r.Handle("/pprof/goroutine", pprof.Handler("goroutine")) |
| 42 | r.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) |
| 43 | r.Handle("/pprof/mutex", pprof.Handler("mutex")) |
| 44 | r.Handle("/pprof/heap", pprof.Handler("heap")) |
| 45 | r.Handle("/pprof/block", pprof.Handler("block")) |
| 46 | r.Handle("/pprof/allocs", pprof.Handler("allocs")) |
| 47 | |
| 48 | return r |
| 49 | } |
nothing calls this directly
no test coverage detected