forked from coredns/coredns
/
setup.go
50 lines (40 loc) · 881 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
47
48
49
50
package loadbalance
import (
"fmt"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/mholt/caddy"
)
var log = clog.NewWithPlugin("loadbalance")
func init() {
caddy.RegisterPlugin("loadbalance", caddy.Plugin{
ServerType: "dns",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
err := parse(c)
if err != nil {
return plugin.Error("loadbalance", err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return RoundRobin{Next: next}
})
return nil
}
func parse(c *caddy.Controller) error {
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
return nil
case 1:
if args[0] != "round_robin" {
return fmt.Errorf("unknown policy: %s", args[0])
}
return nil
}
}
return c.ArgErr()
}