forked from coredns/coredns
/
setup.go
46 lines (37 loc) · 770 Bytes
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
}