config.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_RDDP string //报告库数据库连接
  12. REDIS_CACHE string //缓存地址
  13. Rc *cache.Cache //redis缓存
  14. Re error //redis错误
  15. )
  16. // 微信配置信息
  17. var (
  18. WxId string //微信原始ID
  19. WxAppId string
  20. WxAppSecret string
  21. //内部员工公众号(弘则部门)
  22. AdminWxAppId string
  23. AdminWxAppSecret string
  24. //微信列表
  25. WxAppList map[string]string
  26. WxAppIdCygx string
  27. WxAppSecretCygx string
  28. )
  29. // LibreOfficePath LibreOfficePath的地址
  30. var LibreOfficePath string
  31. func init() {
  32. tmpRunMode, err := web.AppConfig.String("run_mode")
  33. if err != nil {
  34. panic("配置文件读取run_mode错误 " + err.Error())
  35. }
  36. RunMode = tmpRunMode
  37. if RunMode == "" {
  38. localIp, err := GetLocalIP()
  39. fmt.Println("localIp:", localIp)
  40. if localIp == "10.0.0.123" {
  41. RunMode = "debug"
  42. } else {
  43. RunMode = "release"
  44. }
  45. fmt.Println("RunMode:", RunMode)
  46. configPath := `/home/code/config/hongze_public_api/conf/app.conf`
  47. fmt.Println("configPath:", configPath)
  48. err = web.LoadAppConfig("ini", configPath)
  49. if err != nil {
  50. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  51. }
  52. WxRelease()
  53. WxReleaseCygx() // 查研观向小助手
  54. }
  55. config, err := web.AppConfig.GetSection(RunMode)
  56. if err != nil {
  57. panic("配置文件读取错误 " + err.Error())
  58. }
  59. MYSQL_URL = config["mysql_url"]
  60. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  61. REDIS_CACHE = config["beego_cache"]
  62. if len(REDIS_CACHE) <= 0 {
  63. panic("redis链接参数没有配置")
  64. }
  65. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  66. if Re != nil {
  67. fmt.Println(Re)
  68. panic(Re)
  69. }
  70. tmpLibreOfficePath, err := web.AppConfig.String("libreOfficePath")
  71. if err != nil {
  72. panic("配置文件读取libreOfficePath错误 " + err.Error())
  73. }
  74. LibreOfficePath = tmpLibreOfficePath
  75. beeLogger.Log.Info(RunMode + " 模式")
  76. if RunMode == "release" {
  77. } else {
  78. WxDebug()
  79. }
  80. }
  81. // 测试环境模板消息
  82. func WxDebug() {
  83. WxAppId = "wx9b5d7291e581233a"
  84. WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
  85. WxId = "gh_5dc508325c6f"
  86. //内部员工公众号(弘则部门)
  87. AdminWxAppId = "wx1392111da5426e9e"
  88. AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
  89. WxAppList = make(map[string]string)
  90. WxAppList[AdminWxAppId] = AdminWxAppSecret
  91. WxAppList[WxAppId] = WxAppSecret
  92. }
  93. // 生产环境模板消息
  94. func WxRelease() {
  95. WxAppId = "wx4a844c734d8c8e56"
  96. WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
  97. WxId = "gh_b67e0049fb8c"
  98. //内部员工公众号(弘则部门)
  99. AdminWxAppId = "wx1392111da5426e9e"
  100. AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
  101. WxAppList = make(map[string]string)
  102. WxAppList[AdminWxAppId] = AdminWxAppSecret
  103. WxAppList[WxAppId] = WxAppSecret
  104. }
  105. // 查研观向生产环境模板消息
  106. func WxReleaseCygx() {
  107. WxAppIdCygx = "wxb7cb8a15abad5b8e"
  108. WxAppSecretCygx = "f425ba2863084249722af1e2a5cfffd3"
  109. }