-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
110 lines (97 loc) · 1.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package redis
import (
"fmt"
"strconv"
"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
)
func init() {
plugin.Register("redis", setup)
}
func setup(c *caddy.Controller) error {
r, err := redisParse(c)
if err != nil {
return plugin.Error("redis", err)
}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
r.Next = next
return r
})
return nil
}
func redisParse(c *caddy.Controller) (*Redis, error) {
redis := New()
var (
err error
)
fmt.Println("parsing args")
for c.Next() {
//if c.NextBlock() {
for c.NextBlock() {
fmt.Println("printing args")
fmt.Println(c.Val())
switch c.Val() {
case "address":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
fmt.Println(c.Val())
redis.redisAddress = c.Val()
case "password":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
redis.redisPassword = c.Val()
case "prefix":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
redis.keyPrefix = c.Val()
case "suffix":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
redis.keySuffix = c.Val()
case "connect_timeout":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
redis.connectTimeout, err = strconv.Atoi(c.Val())
if err != nil {
redis.connectTimeout = 0
}
case "read_timeout":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
redis.readTimeout, err = strconv.Atoi(c.Val())
if err != nil {
redis.readTimeout = 0
}
case "ttl":
if !c.NextArg() {
return &Redis{}, c.ArgErr()
}
var val int
val, err = strconv.Atoi(c.Val())
if err != nil {
val = defaultTtl
}
redis.Ttl = uint32(val)
default:
if c.Val() != "}" {
return &Redis{}, c.Errf("unknown property '%s'", c.Val())
}
}
// if !c.Next() {
// break
// }
}
//}
redis.Connect()
redis.LoadZones()
return redis, nil
}
return &Redis{}, nil
}