golang 的 rabbitmq 消费项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

init_cfg.go 1.5 KiB

2 jaren geleden
1 jaar geleden
5 maanden geleden
2 jaren geleden
1 jaar geleden
1 jaar geleden
2 jaren geleden
1 jaar geleden
2 jaren geleden
1 jaar geleden
1 jaar geleden
1 jaar geleden
5 maanden geleden
2 jaren geleden
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package cfg
  2. import (
  3. "flag"
  4. "io/ioutil"
  5. "gopkg.in/yaml.v2"
  6. )
  7. //配置文件数据,全局变量
  8. var (
  9. Debug bool
  10. Prd bool
  11. CurlDebug bool
  12. RedisAddr string
  13. DB *DBCfg
  14. DataDB *DBCfg
  15. ImDB *DBCfg
  16. MQ *MQCfg
  17. ES *ESCfg
  18. Log *LogCfg
  19. Admin *AdminCfg
  20. ImBusinessRpc *ImBusinessRpcCfg
  21. ImLogicRpc *ImLogicRpcCfg
  22. Local bool
  23. AppComm *AppCommCfg
  24. WxappletFilepath *WxappletFilepathCfg
  25. ZhimengDB *DBCfg
  26. )
  27. //初始化配置文件,将cfg.yml读入到内存
  28. func InitCfg() {
  29. //用指定的名称、默认值、使用信息注册一个string类型flag。
  30. path := flag.String("c", "etc/cfg.yml", "config file")
  31. //解析命令行参数写入注册的flag里。
  32. //解析之后,flag的值可以直接使用。
  33. flag.Parse()
  34. var (
  35. c []byte
  36. err error
  37. conf *Config
  38. )
  39. if c, err = ioutil.ReadFile(*path); err != nil {
  40. panic(err)
  41. }
  42. //yaml.Unmarshal反序列化映射到Config
  43. if err = yaml.Unmarshal(c, &conf); err != nil {
  44. panic(err)
  45. }
  46. //数据读入内存
  47. Prd = conf.Prd
  48. Debug = conf.Debug
  49. Local = conf.Local
  50. CurlDebug = conf.CurlDebug
  51. DB = &conf.DB
  52. DataDB = &conf.DataDB
  53. ImDB = &conf.ImDB
  54. Log = &conf.Log
  55. RedisAddr = conf.RedisAddr
  56. Admin = &conf.Admin
  57. AppComm = &conf.AppComm
  58. MQ = &conf.MQ
  59. ES = &conf.ES
  60. ImBusinessRpc = &conf.ImBusinessRpc
  61. ImLogicRpc = &conf.ImLogicRpc
  62. WxappletFilepath = &conf.WxappletFilepath
  63. ZhimengDB = &conf.ZhimengDB
  64. }