loader.go
837 字节
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
package constant
import (
"github.com/astaxie/beego"
)
var config = NewConfigLoader()
type ConfigLoader struct {
History map[string]interface{}
HistorySort []string
}
func NewConfigLoader() *ConfigLoader {
return &ConfigLoader{
History: make(map[string]interface{}),
HistorySort: make([]string, 0),
}
}
func (c *ConfigLoader) String(key string) (ret string, ok bool) {
if ret = beego.AppConfig.String(key); len(ret) != 0 {
ok = true
c.SetHistory(key, ret)
return
}
return
}
func (c *ConfigLoader) StringDefault(key string, defaultValue string) string {
if ret, ok := c.String(key); ok {
return ret
}
return defaultValue
}
func (c *ConfigLoader) SetHistory(key string, value interface{}) {
if _, ok := c.History[key]; !ok {
c.History[key] = value
c.HistorySort = append(c.HistorySort, key)
}
}