coredns/middleware/health/setup.go
Yong Tang 81af74aad0 Fix import path github.com/miekg/coredns -> github.com/coredns/coredns (#547)
This fix fixes import path from
`github.com/miekg/coredns`
->
`github.com/coredns/coredns`
2017-02-22 06:51:47 +00:00

46 lines
770 B
Go

package health
import (
"github.com/coredns/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)
}
h := &health{Addr: addr}
c.OnStartup(h.Startup)
c.OnShutdown(h.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
}