config.go
872 Bytes
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
package common
import (
	"github.com/BurntSushi/toml"
)
// Configs 全局配置信息
type Configs struct {
	Listen     string
	ApiToken   string
	Gomaxprocs int
	Statsd     *StatsdConfig
	Log        *LogConfig
	Mysql		*MysqlConfig
}
// LogConfig 日志相关配置信息
type LogConfig struct {
	Level string
}
// StatsdConfig Statsd相关配置信息
type StatsdConfig struct {
	Addr   string
	Prefix string
}
//mysql配置
type MysqlConfig struct {
	Dsn     string
	MaxIdle int
	MaxOpen int
}
// Config 全局配置信息
var Config *Configs
// InitConfig 加载配置
func InitConfig(path string) {
	config, err := loadConfig(path)
	if err != nil {
		panic(err)
	}
	Config = config
}
func loadConfig(path string) (*Configs, error) {
	config := new(Configs)
	if _, err := toml.DecodeFile(path, config); err != nil {
		return nil, err
	}
	return config, nil
}