coredns/middleware/health/setup.go
Miek Gieben 2dd8a687b3 Startup notification (#250)
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.
2016-09-10 09:16:25 +01:00

46 lines
783 B
Go

package health
import (
"github.com/miekg/coredns/middleware"
"github.com/mholt/caddy"
)
func init() {
caddy.RegisterPlugin("health", caddy.Plugin{
ServerType: "dns",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
addr, err := healthParse(c)
if err != nil {
return middleware.Error("health", err)
}
health := &Health{Addr: addr}
c.OnStartup(health.Startup)
c.OnShutdown(health.Shutdown)
// Don't do AddMiddleware, as health is not *really* a middleware just a separate
// webserver running.
return nil
}
func healthParse(c *caddy.Controller) (string, error) {
addr := ""
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
case 1:
addr = args[0]
default:
return "", c.ArgErr()
}
}
return addr, nil
}