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

2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. SrvAddr string
  13. RedisAddr string
  14. DB *DBCfg
  15. DataDB *DBCfg
  16. MQ *MQCfg
  17. ES *ESCfg
  18. Log *LogCfg
  19. ArkID *ArkIDCfg
  20. Admin *AdminCfg
  21. Official *OfficialCfg
  22. WxappletFilepath *WxappletFilepathCfg
  23. Local bool
  24. AppComm *AppCommCfg
  25. MqWorkQueueName string
  26. RabbitMqAddr string
  27. )
  28. //初始化配置文件,将cfg.yml读入到内存
  29. func InitCfg() {
  30. //用指定的名称、默认值、使用信息注册一个string类型flag。
  31. path := flag.String("c", "etc/cfg.yml", "config file")
  32. //解析命令行参数写入注册的flag里。
  33. //解析之后,flag的值可以直接使用。
  34. flag.Parse()
  35. var (
  36. c []byte
  37. err error
  38. conf *Config
  39. )
  40. if c, err = ioutil.ReadFile(*path); err != nil {
  41. panic(err)
  42. }
  43. //yaml.Unmarshal反序列化映射到Config
  44. if err = yaml.Unmarshal(c, &conf); err != nil {
  45. panic(err)
  46. }
  47. //数据读入内存
  48. Prd = conf.Prd
  49. Debug = conf.Debug
  50. Local = conf.Local
  51. CurlDebug = conf.CurlDebug
  52. DB = &conf.DB
  53. DataDB = &conf.DataDB
  54. Log = &conf.Log
  55. ArkID = &conf.ArkID
  56. RedisAddr = conf.RedisAddr
  57. SrvAddr = conf.SrvAddr
  58. Admin = &conf.Admin
  59. Official = &conf.Official
  60. WxappletFilepath = &conf.WxappletFilepath
  61. AppComm = &conf.AppComm
  62. MqWorkQueueName = conf.MqWorkQueueName
  63. RabbitMqAddr = conf.RabbitMqAddrTest
  64. if conf.Prd {
  65. RabbitMqAddr = conf.RabbitMqAddr
  66. }
  67. MQ = &conf.MQ
  68. ES = &conf.ES
  69. }