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.3 KiB

2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. )
  25. //初始化配置文件,将cfg.yml读入到内存
  26. func InitCfg() {
  27. //用指定的名称、默认值、使用信息注册一个string类型flag。
  28. path := flag.String("c", "etc/cfg.yml", "config file")
  29. //解析命令行参数写入注册的flag里。
  30. //解析之后,flag的值可以直接使用。
  31. flag.Parse()
  32. var (
  33. c []byte
  34. err error
  35. conf *Config
  36. )
  37. if c, err = ioutil.ReadFile(*path); err != nil {
  38. panic(err)
  39. }
  40. //yaml.Unmarshal反序列化映射到Config
  41. if err = yaml.Unmarshal(c, &conf); err != nil {
  42. panic(err)
  43. }
  44. //数据读入内存
  45. Prd = conf.Prd
  46. Debug = conf.Debug
  47. Local = conf.Local
  48. CurlDebug = conf.CurlDebug
  49. DB = &conf.DB
  50. DataDB = &conf.DataDB
  51. ImDB = &conf.ImDB
  52. Log = &conf.Log
  53. RedisAddr = conf.RedisAddr
  54. Admin = &conf.Admin
  55. AppComm = &conf.AppComm
  56. MQ = &conf.MQ
  57. ES = &conf.ES
  58. ImBusinessRpc = &conf.ImBusinessRpc
  59. ImLogicRpc = &conf.ImLogicRpc
  60. }