附近小店
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.

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