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

преди 1 седмица
преди 5 дни
преди 1 седмица
преди 5 дни
преди 1 седмица
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. SrvAddr string
  12. SmartCanteenPay string
  13. RedisAddr string
  14. RedisPassword string
  15. DB *DBCfg
  16. MQ *MQCfg
  17. ES *ESCfg
  18. Log *LogCfg
  19. ImBusinessRpc *ImBusinessRpcCfg
  20. ImLogicRpc *ImLogicRpcCfg
  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. DB = &conf.DB
  45. Log = &conf.Log
  46. RedisAddr = conf.RedisAddr
  47. RedisPassword = conf.RedisPassword
  48. SrvAddr = conf.SrvAddr
  49. MQ = &conf.MQ
  50. ES = &conf.ES
  51. ImBusinessRpc = &conf.ImBusinessRpc
  52. ImLogicRpc = &conf.ImLogicRpc
  53. }