-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
44 lines (33 loc) · 819 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
package dcache
import (
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
)
func init() {
plugin.Register(name, setup)
}
func setup(c *caddy.Controller) error {
var log = clog.NewWithPlugin(name)
for i := 2; i != 0; i-- {
if !c.Next() {
return c.SyntaxErr("dcache redishost:port")
}
}
host := c.Val()
log.Infof("dcache connect to host name %s", host)
dcache := New(host)
dcache.log = log
if err := dcache.connect(); err != nil {
return plugin.Error(name, err)
}
log.Info("redis connect success")
go dcache.runSubscribe()
go dcache.runPublish()
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
dcache.Next = next
return dcache
})
return nil
}