蛋蛋星球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.
 
 
 
 
 
 

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