-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.go
59 lines (50 loc) · 1.11 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
package redis
import (
"fmt"
"github.com/caddyserver/caddy"
"github.com/caddyserver/caddy/caddyhttp/httpserver"
)
func init() {
caddy.RegisterPlugin("redis", caddy.Plugin{
ServerType: "http",
Action: setup,
})
}
func setup(c *caddy.Controller) error {
// Parse the arguments
server, password, err := parse(c)
if err != nil {
return err
}
// Set the server and password for the redis pool
pool = newPool(server, password)
cfg := httpserver.GetConfig(c)
mid := func(next httpserver.Handler) httpserver.Handler {
return Redis{Next: next}
}
cfg.AddMiddleware(mid)
return nil
}
func parse(c *caddy.Controller) (string, string, error) {
server := ":6379"
password := ""
for c.Next() {
for c.NextBlock() {
switch c.Val() {
case "server":
if !c.NextArg() {
return server, password, c.ArgErr()
}
server = c.Val()
fmt.Println(LogTag, "Found server config:", server)
case "password":
if !c.NextArg() {
return server, password, c.ArgErr()
}
password = c.Val()
fmt.Println(LogTag, "Found password config:", password)
}
}
}
return server, password, nil
}