-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
60 lines (49 loc) · 1.21 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
package dnstun
import (
"strings"
"github.com/caddyserver/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
)
func init() { plugin.Register("dnstun", setup) }
func setup(c *caddy.Controller) error {
opts, err := parseOptions(c)
if err != nil {
return plugin.Error("dnstun", err)
}
p := NewDnstun(opts)
dnsserver.GetConfig(c).AddPlugin(newChainHandler(p))
return nil
}
func parseOptions(c *caddy.Controller) (opts Options, err error) {
c.Next() // directive name
opts.Mapping = MappingForward
for c.NextBlock() {
switch c.Val() {
case "runtime":
if !c.Args(&opts.Runtime) {
return opts, c.ArgErr()
}
case "mapping":
if !c.Args(&opts.Mapping) {
return opts, c.ArgErr()
}
if _, ok := mappings[opts.Mapping]; !ok {
return opts, c.Errf("unknown mapping %q", opts.Mapping)
}
case "detector":
var detector string
if !c.Args(&detector) {
return opts, c.ArgErr()
}
tuple := strings.SplitN(detector, ":", 2)
if len(tuple) != 2 {
return opts, c.Errf("unknown detector name %q", detector)
}
opts.Model, opts.Version = tuple[0], tuple[1]
default:
return opts, c.Errf("unknown property %q", c.Val())
}
}
return
}