toml 总体上要比yaml和json更加优雅
包地址github.com/BurnSushi/toml
var (
MySql *MySqlConf
Redis *RedisConf
IMService *IMServiceConf
ApiHttpService *ApiHttpServiceConf
)
type MySqlConf struct {
Host string
Port int
Username string
Password string
Db string
Charset string
}
type RedisConf struct {
Host string
Port int
Password string
Db int
}
type IMServiceConf struct {
Addr string
Service string
Port int
}
type ApiHttpServiceConf struct {
Addr string
Port int
}
type config struct {
MySql MySqlConf
Redis RedisConf
IMService IMServiceConf
ApiHttp ApiHttpServiceConf
}
func init() {
var conf config
c := getConfigPath()
logger.D("config path: %s", c)
_, err := toml.DecodeFile(c, &conf)
if err != nil {
panic(fmt.Sprintf("error on load config: %s", err.Error()))
}
MySql = &conf.MySql
Redis = &conf.Redis
IMService = &conf.IMService
ApiHttpService = &conf.ApiHttp
}