|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package cfg
-
- import (
- "flag"
- "io/ioutil"
-
- "gopkg.in/yaml.v2"
- )
-
- //配置文件数据,全局变量
- var (
- Debug bool
- Prd bool
- CurlDebug bool
- RedisAddr string
- DB *DBCfg
- DataDB *DBCfg
- ImDB *DBCfg
- MQ *MQCfg
- ES *ESCfg
- Log *LogCfg
- Admin *AdminCfg
- ImBusinessRpc *ImBusinessRpcCfg
- ImLogicRpc *ImLogicRpcCfg
- Local bool
- AppComm *AppCommCfg
- WxappletFilepath *WxappletFilepathCfg
- ArkID *ArkIDCfg
- )
-
- //初始化配置文件,将cfg.yml读入到内存
- func InitCfg() {
- //用指定的名称、默认值、使用信息注册一个string类型flag。
- path := flag.String("c", "etc/cfg.yml", "config file")
- //解析命令行参数写入注册的flag里。
- //解析之后,flag的值可以直接使用。
- flag.Parse()
- var (
- c []byte
- err error
- conf *Config
- )
- if c, err = ioutil.ReadFile(*path); err != nil {
- panic(err)
- }
- //yaml.Unmarshal反序列化映射到Config
- if err = yaml.Unmarshal(c, &conf); err != nil {
- panic(err)
- }
- //数据读入内存
- Prd = conf.Prd
- Debug = conf.Debug
- Local = conf.Local
- CurlDebug = conf.CurlDebug
- DB = &conf.DB
- DataDB = &conf.DataDB
- ImDB = &conf.ImDB
- Log = &conf.Log
- RedisAddr = conf.RedisAddr
- Admin = &conf.Admin
- AppComm = &conf.AppComm
- MQ = &conf.MQ
- ES = &conf.ES
- ImBusinessRpc = &conf.ImBusinessRpc
- ImLogicRpc = &conf.ImLogicRpc
- WxappletFilepath = &conf.WxappletFilepath
- ArkID = &conf.ArkID
- }
|