aboutsummaryrefslogtreecommitdiff
path: root/middleware/health/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'middleware/health/setup.go')
-rw-r--r--middleware/health/setup.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/middleware/health/setup.go b/middleware/health/setup.go
new file mode 100644
index 000000000..cf7667d17
--- /dev/null
+++ b/middleware/health/setup.go
@@ -0,0 +1,42 @@
+package health
+
+import "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 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
+}