package pprof import ( "net/http" "net/http/pprof" "time" "github.com/gorilla/mux" ) // Server serves a new pprof http server func Serve(addr string) error { router := Router() server := &http.Server{ Addr: addr, Handler: router, ReadHeaderTimeout: 3 * time.Second, } return server.ListenAndServe() } // Router returns a new router with list of pprof endpoints func Router() *mux.Router { r := mux.NewRouter() r.PathPrefix("/debug/").Handler(http.DefaultServeMux) r.HandleFunc("/debug/pprof/", pprof.Index) r.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) r.HandleFunc("/debug/pprof/profile", pprof.Profile) r.HandleFunc("/debug/pprof/symbol", pprof.Symbol) r.HandleFunc("/debug/pprof/trace", pprof.Trace) return r }