// Package httpdebug provides HTTP handler for debug endpoints.
package httpdebug import ( ) // New returns a new HTTP handler for debug endpoints. func () http.Handler { := http.NewServeMux() handlePprof() handleExpvar() handleNetTrace(, true) handleBuildInfo() handleIndex() return } func ( *http.ServeMux) { .HandleFunc("GET /debug/pprof/", pprof.Index) .HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline) .HandleFunc("GET /debug/pprof/profile", pprof.Profile) .HandleFunc("GET /debug/pprof/symbol", pprof.Symbol) .HandleFunc("GET /debug/pprof/trace", pprof.Trace) } func ( *http.ServeMux) { .Handle("GET /debug/vars", expvar.Handler()) } func ( *http.ServeMux, bool) { .HandleFunc("GET /debug/requests", func( http.ResponseWriter, *http.Request) { .Header().Set("Content-Type", "text/html; charset=utf-8") trace.Render(, , ) }) .HandleFunc("GET /debug/events", func( http.ResponseWriter, *http.Request) { .Header().Set("Content-Type", "text/html; charset=utf-8") trace.RenderEvents(, , ) }) } func ( *http.ServeMux) { .HandleFunc("GET /debug/buildinfo", serveBuildInfo) } func ( http.ResponseWriter, *http.Request) { , := debug.ReadBuildInfo() if ! { = &debug.BuildInfo{GoVersion: runtime.Version()} } // TODO: support JSON responses; see also https://go.dev/issue/19307 := .String() := .Header() .Set("Content-Type", "text/plain; charset=utf-8") .Set("Content-Length", strconv.Itoa(len())) _, _ = io.WriteString(, ) } func ( *http.ServeMux) { .HandleFunc("/debug/", serveIndex) } func ( http.ResponseWriter, *http.Request) { := .Header() .Set("Content-Type", "text/html; charset=utf-8") .Set("Content-Length", strconv.Itoa(len(debugPage))) _, _ = io.WriteString(, debugPage) } const debugPage = `<!doctype html> <html lang=en> <title>Debug</title> <meta name=viewport content="width=device-width"> <ul> <li><a href=/debug/pprof>pprof</a></li> <li><a href=/debug/vars>expvar</a></li> <li><a href=/debug/events>events</a></li> <li><a href=/debug/requests>traces</a></li> <li><a href=/debug/buildinfo>build info</a></li> </ul> `