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.
 
 
 

67 lines
1.5 KiB

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