2016-06-06 11:51:56 +08:00
|
|
|
package pprof
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mholt/caddy"
|
|
|
|
"github.com/mholt/caddy/caddyhttp/httpserver"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2016-06-07 05:31:03 +08:00
|
|
|
caddy.RegisterPlugin("pprof", caddy.Plugin{
|
2016-06-06 11:51:56 +08:00
|
|
|
ServerType: "http",
|
|
|
|
Action: setup,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup returns a new instance of a pprof handler. It accepts no arguments or options.
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
|
|
found := false
|
|
|
|
|
|
|
|
for c.Next() {
|
|
|
|
if found {
|
|
|
|
return c.Err("pprof can only be specified once")
|
|
|
|
}
|
|
|
|
if len(c.RemainingArgs()) != 0 {
|
|
|
|
return c.ArgErr()
|
|
|
|
}
|
|
|
|
if c.NextBlock() {
|
|
|
|
return c.ArgErr()
|
|
|
|
}
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
|
2016-06-21 01:44:20 +08:00
|
|
|
httpserver.GetConfig(c).AddMiddleware(func(next httpserver.Handler) httpserver.Handler {
|
2016-06-06 11:51:56 +08:00
|
|
|
return &Handler{Next: next, Mux: NewMux()}
|
|
|
|
})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|