-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
34 lines (30 loc) · 936 Bytes
/
config.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
package gomacaron
import (
"fmt"
"github.com/go-macaron/cache"
)
// ConfigParser config parser for gomacaron
func ConfigParser(conf interface{}) cache.Options {
cfg := make(map[string]interface{})
if fmt.Sprintf("%T", conf) != "map[string]interface {}" {
cfg["adapter"] = "redis"
cfg["adapterConfig"] = "addr:127.0.0.1:6379"
cfg["interval"] = 60
cfg["occupyMode"] = false
cfg["section"] = "cache"
} else {
conf := conf.(map[string]interface{})
cfg["adapter"] = conf["adapter"]
cfg["adapterConfig"] = conf["adapterconfig"]
cfg["interval"] = conf["interval"]
cfg["occupyMode"] = conf["occupymode"]
cfg["section"] = conf["section"]
}
return cache.Options{
Adapter: fmt.Sprintf("%s", cfg["adapter"]),
AdapterConfig: fmt.Sprintf("%s", cfg["adapterConfig"]),
Interval: cfg["interval"].(int),
OccupyMode: cfg["occupyMode"].(bool),
Section: fmt.Sprintf("%s", cfg["section"]),
}
}