1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

web: Optionally mount /debug/pprof for #120

- web: eliminate use of http.DefaultServeMux
This commit is contained in:
James Hillyerd
2018-10-20 16:16:09 -07:00
parent 5e8f00fe0b
commit 98745b3bb9
4 changed files with 29 additions and 2 deletions

View File

@@ -100,6 +100,7 @@ type Web struct {
CookieAuthKey string `desc:"Session cipher key (text)"`
MonitorVisible bool `required:"true" default:"true" desc:"Show monitor tab in UI?"`
MonitorHistory int `required:"true" default:"30" desc:"Monitor remembered messages"`
PProf bool `required:"true" default:"false" desc:"Expose profiling tools on /debug/pprof"`
}
// Storage contains the mail store configuration.

View File

@@ -6,6 +6,7 @@ import (
"expvar"
"net"
"net/http"
"net/http/pprof"
"path/filepath"
"time"
@@ -70,7 +71,16 @@ func Initialize(
Msg("Web UI content mapped")
Router.PathPrefix("/public/").Handler(http.StripPrefix("/public/",
http.FileServer(http.Dir(staticPath))))
http.Handle("/", Router)
Router.Handle("/debug/vars", expvar.Handler())
if conf.Web.PProf {
Router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
Router.HandleFunc("/debug/pprof/profile", pprof.Profile)
Router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
Router.HandleFunc("/debug/pprof/trace", pprof.Trace)
Router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index)
log.Warn().Str("module", "web").Str("phase", "startup").
Msg("Go pprof tools installed to /debug/pprof")
}
// Session cookie setup
if conf.Web.CookieAuthKey == "" {
@@ -88,7 +98,7 @@ func Initialize(
func Start(ctx context.Context) {
server = &http.Server{
Addr: rootConfig.Web.Addr,
Handler: nil,
Handler: Router,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
}