-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
45 lines (38 loc) · 877 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
package epicmdns
import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/epiclabs-io/epicmdns/mdns"
)
// register with CoreDNS on module load
func init() {
caddy.RegisterPlugin("epicmdns", caddy.Plugin{
ServerType: "dns",
Action: setup,
})
}
// setup parses the configuration and launches the plug-in
func setup(c *caddy.Controller) error {
// parse configuration
config, err := parseConfig(&c.Dispenser)
if err != nil {
return err
}
// instantiate mdns resolver
mdnsClient, err := mdns.New(&config.Config)
if err != nil {
return err
}
// setup plugin
p := mdnsPlugin{
mdns: mdnsClient,
domain: config.Domain,
}
// Add plug-in to the chain
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
p.Next = next
return p
})
return nil
}