-
Notifications
You must be signed in to change notification settings - Fork 22
/
config.go
54 lines (42 loc) · 865 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/astaxie/beego/config"
)
type Config struct {
Addr string
LogDir string
LogLevel string
ExpireDays int
cnfPath string
innerCnf config.Configer
}
func NewConfig() *Config {
cnf := &Config{}
return cnf
}
func (o *Config) Load(cnfPath string) error {
var err error
o.cnfPath = cnfPath
err = o.Reload()
if err != nil {
return err
}
return nil
}
func (o *Config) Reload() error {
var err error
if o.cnfPath != "" {
o.innerCnf, err = config.NewConfig("ini", o.cnfPath)
if err != nil {
log.Error(err)
return err
}
} else {
o.innerCnf = config.NewFakeConfig()
}
o.LogDir = o.innerCnf.DefaultString("log::dir", "../log")
o.LogLevel = o.innerCnf.DefaultString("log::level", "info")
o.ExpireDays = o.innerCnf.DefaultInt("expire_days", 7)
return nil
}