-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.go
63 lines (53 loc) · 1.3 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
package finalize
import (
"fmt"
"strconv"
"strings"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
)
// init registers this plugin.
func init() { plugin.Register("finalize", setup) }
func setup(c *caddy.Controller) error {
finalize, err := parse(c)
if err != nil {
return plugin.Error("finalize", err)
}
// Add the Plugin to CoreDNS, so Servers can use it in their plugin chain.
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
finalize.Next = next
return finalize
})
log.Debug("Added plugin to server")
return nil
}
func parse(c *caddy.Controller) (*Finalize, error) {
finalizePlugin := New()
for c.Next() {
args := c.RemainingArgs()
switch len(args) {
case 0:
// do nothing
case 1:
return nil, c.ArgErr()
case 2:
if strings.EqualFold("max_depth", args[0]) {
n, err := strconv.Atoi(args[1])
if err != nil {
return nil, err
}
if n <= 0 {
return nil, fmt.Errorf("max_depth parameter must be greater than 0")
}
finalizePlugin.maxDepth = n
} else {
return nil, fmt.Errorf("unsupported parameter %s for upstream setting", args[0])
}
default:
return nil, c.ArgErr()
}
}
log.Debug("Successfully parsed configuration")
return finalizePlugin, nil
}