Stop the caddy message and start our own init notifications. Log the version of CoreDNS when starting up. Fix all middleware's setup functions so that return the error prefixed with *which* middleware was failing; leads to better debuggable errors when starting up.
41 lines
710 B
Go
41 lines
710 B
Go
package pprof
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mholt/caddy"
|
|
"github.com/miekg/coredns/middleware"
|
|
)
|
|
|
|
func init() {
|
|
caddy.RegisterPlugin("pprof", caddy.Plugin{
|
|
ServerType: "dns",
|
|
Action: setup,
|
|
})
|
|
}
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
found := false
|
|
for c.Next() {
|
|
if found {
|
|
return middleware.Error("pprof", c.Err("pprof can only be specified once"))
|
|
}
|
|
if len(c.RemainingArgs()) != 0 {
|
|
return middleware.Error("pprof", c.ArgErr())
|
|
}
|
|
if c.NextBlock() {
|
|
return middleware.Error("pprof", c.ArgErr())
|
|
}
|
|
found = true
|
|
}
|
|
|
|
handler := &Handler{}
|
|
pprofOnce.Do(func() {
|
|
c.OnStartup(handler.Startup)
|
|
c.OnShutdown(handler.Shutdown)
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
var pprofOnce sync.Once
|