Something went wrong. Try again.
forked from darkweak/souin
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788package debug
import ( "net/http" "net/http/pprof" "strings"
"github.com/darkweak/souin/configurationtypes")
// DebugAPI object contains informations related to the endpointstype DebugAPI struct { basePath string enabled bool}
type DefaultHandler struct{}
func (d *DefaultHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { pprof.Index(w, r)}
// InitializeDebug initialize the debug endpointsfunc InitializeDebug(configuration configurationtypes.AbstractConfigurationInterface) *DebugAPI { basePath := configuration.GetAPI().Debug.BasePath enabled := configuration.GetAPI().Debug.Enable if basePath == "" { basePath = "/debug/" }
return &DebugAPI{ basePath, enabled, }}
// GetBasePath will return the basepath for this resourcefunc (p *DebugAPI) GetBasePath() string { return p.basePath}
// IsEnabled will return enabled statusfunc (p *DebugAPI) IsEnabled() bool { return p.enabled}
// HandleRequest will handle the requestfunc (p *DebugAPI) HandleRequest(w http.ResponseWriter, r *http.Request) { var executor http.Handler executor = &DefaultHandler{}
if strings.Contains(r.RequestURI, "allocs") { executor = pprof.Handler("allocs") } if strings.Contains(r.RequestURI, "cmdline") { executor = pprof.Handler("cmdline") } if strings.Contains(r.RequestURI, "profile") { executor = pprof.Handler("profile") } if strings.Contains(r.RequestURI, "symbol") { executor = pprof.Handler("symbol") } if strings.Contains(r.RequestURI, "trace") { executor = pprof.Handler("trace") } if strings.Contains(r.RequestURI, "goroutine") { executor = pprof.Handler("goroutine") } if strings.Contains(r.RequestURI, "heap") { executor = pprof.Handler("heap") } if strings.Contains(r.RequestURI, "block") { executor = pprof.Handler("block") } if strings.Contains(r.RequestURI, "heap") { executor = pprof.Handler("heap") } if strings.Contains(r.RequestURI, "mutex") { executor = pprof.Handler("mutex") } if strings.Contains(r.RequestURI, "threadcreate") { executor = pprof.Handler("threadcreate") }
executor.ServeHTTP(w, r)}