forked from gqf2008/babylon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
67 lines (58 loc) · 1.22 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
log "github.com/cihub/seelog"
"github.com/kless/goconfig/config"
"os"
"path/filepath"
)
var Config *config.Config
var main_config_file string
func config_init(file string) error {
f, err := os.Open(file)
defer f.Close()
if err == nil {
Config, err = config.ReadDefault(file)
main_config_file = file
}
return err
}
func log_init() {
defer log.Flush()
logger, e := log.LoggerFromConfigAsFile(GetConfigDir() + "/log.conf")
if e != nil {
log.Criticalf("Error %v", e)
}
log.ReplaceLogger(logger)
//TODO timer watch config file
}
func GetConfigDir() string {
return filepath.Dir(main_config_file)
}
func GetString(section, key, def string) string {
v, err := Config.String(section, key)
if err != nil {
return def
}
return v
}
func GetInt(section, key string, def int) int {
v, err := Config.Int(section, key)
if err != nil {
return def
}
return v
}
func GetFloat(section, key string, def float64) float64 {
v, err := Config.Float(section, key)
if err != nil {
return def
}
return v
}
func GetBool(section, key string, def bool) bool {
v, err := Config.Bool(section, key)
if err != nil {
return def
}
return v
}