config.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. REDIS_CACHE string //缓存地址
  12. Rc *cache.Cache //redis缓存
  13. Re error //redis错误
  14. )
  15. //微信配置信息
  16. var (
  17. WxId string //微信原始ID
  18. WxAppId string
  19. WxAppSecret string
  20. //内部员工公众号(弘则部门)
  21. AdminWxAppId string
  22. AdminWxAppSecret string
  23. //微信列表
  24. WxAppList map[string]string
  25. )
  26. // LibreOfficePath LibreOfficePath的地址
  27. var LibreOfficePath string
  28. func init() {
  29. tmpRunMode, err := web.AppConfig.String("run_mode")
  30. if err != nil {
  31. panic("配置文件读取run_mode错误 " + err.Error())
  32. }
  33. RunMode = tmpRunMode
  34. if RunMode == "" {
  35. localIp, err := GetLocalIP()
  36. fmt.Println("localIp:", localIp)
  37. if localIp == "10.0.0.123" {
  38. RunMode = "debug"
  39. } else {
  40. RunMode = "release"
  41. }
  42. fmt.Println("RunMode:", RunMode)
  43. configPath := `/home/code/config/hongze_public_api/conf/app.conf`
  44. fmt.Println("configPath:", configPath)
  45. err = web.LoadAppConfig("ini", configPath)
  46. if err != nil {
  47. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  48. }
  49. WxRelease()
  50. }
  51. config, err := web.AppConfig.GetSection(RunMode)
  52. if err != nil {
  53. panic("配置文件读取错误 " + err.Error())
  54. }
  55. MYSQL_URL = config["mysql_url"]
  56. REDIS_CACHE = config["beego_cache"]
  57. if len(REDIS_CACHE) <= 0 {
  58. panic("redis链接参数没有配置")
  59. }
  60. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  61. if Re != nil {
  62. fmt.Println(Re)
  63. panic(Re)
  64. }
  65. tmpLibreOfficePath, err := web.AppConfig.String("libreOfficePath")
  66. if err != nil {
  67. panic("配置文件读取libreOfficePath错误 " + err.Error())
  68. }
  69. LibreOfficePath = tmpLibreOfficePath
  70. beeLogger.Log.Info(RunMode + " 模式")
  71. if RunMode == "release" {
  72. } else {
  73. WxDebug()
  74. }
  75. }
  76. //测试环境模板消息
  77. func WxDebug() {
  78. WxAppId = "wx9b5d7291e581233a"
  79. WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
  80. WxId = "gh_5dc508325c6f"
  81. //内部员工公众号(弘则部门)
  82. AdminWxAppId = "wx1392111da5426e9e"
  83. AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
  84. WxAppList = make(map[string]string)
  85. WxAppList[AdminWxAppId] = AdminWxAppSecret
  86. }
  87. //生产环境模板消息
  88. func WxRelease() {
  89. WxAppId = "wx4a844c734d8c8e56"
  90. WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
  91. WxId = "gh_b67e0049fb8c"
  92. //内部员工公众号(弘则部门)
  93. AdminWxAppId = "wx1392111da5426e9e"
  94. AdminWxAppSecret = "30eceb7cf29bf2f046031155ab55d7b4"
  95. WxAppList = make(map[string]string)
  96. WxAppList[AdminWxAppId] = AdminWxAppSecret
  97. }