config.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/server/web"
  5. "github.com/rdlucklib/rdluck_tools/cache"
  6. "strconv"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_CYGX 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. WxPublicAppId string //查研观向小助手公众号
  22. WxPublicAppSecret string //查研观向小助手公众号
  23. HeadimgurlDefault string //默认头像
  24. )
  25. // 日志配置
  26. var (
  27. LogPath string //调用过程中的日志存放地址
  28. LogFile string
  29. LogDataPath string //调用过程中图表相关的日志存放地址
  30. LogDataFile string
  31. BinLogPath string //数据库相关的日志存放地址
  32. BinLogFile string
  33. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  34. ApiLogFile string
  35. LogMaxDays int //日志最大保留天数
  36. )
  37. func init() {
  38. tmpRunMode, err := web.AppConfig.String("run_mode")
  39. if err != nil {
  40. panic("配置文件读取run_mode错误 " + err.Error())
  41. }
  42. RunMode = tmpRunMode
  43. if RunMode == "" {
  44. localIp, err := GetLocalIP()
  45. fmt.Println("localIp:", localIp)
  46. if localIp == "10.0.0.123" {
  47. RunMode = "debug"
  48. } else {
  49. RunMode = "release"
  50. }
  51. configPath := `/home/code/config/hongze_cygxzs/conf/app.conf`
  52. err = web.LoadAppConfig("ini", configPath)
  53. if err != nil {
  54. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  55. }
  56. }
  57. config, err := web.AppConfig.GetSection(RunMode)
  58. if err != nil {
  59. panic("配置文件读取错误 " + err.Error())
  60. }
  61. fmt.Println(RunMode + " 模式")
  62. MYSQL_URL = config["mysql_url"]
  63. MYSQL_URL_CYGX = config["mysql_url_cygx"]
  64. REDIS_CACHE = config["beego_cache"]
  65. if len(REDIS_CACHE) <= 0 {
  66. panic("redis链接参数没有配置")
  67. }
  68. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  69. if Re != nil {
  70. fmt.Println(Re)
  71. panic(Re)
  72. }
  73. if RunMode == "release" {
  74. WxPublicAppId = "wxb7cb8a15abad5b8e" //查研观向小助手
  75. WxPublicAppSecret = "f425ba2863084249722af1e2a5cfffd3" //查研观向小助手
  76. WxId = "gh_ef7675f65027" //查研观向小助手公众号原始ID
  77. } else {
  78. WxPublicAppId = "wx9b5d7291e581233a" //弘则投研公众号 开发者ID(AppID)
  79. WxPublicAppSecret = "f4d52e34021eee262dce9682b31f8861" //弘则投研公众号秘钥
  80. WxId = "gh_5dc508325c6f" //弘则投研公众号原始ID
  81. }
  82. HeadimgurlDefault = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202202/20220225/XFBBOUmDC5AXkfxnHiuqKpPtoofH.png"
  83. //日志配置
  84. {
  85. LogPath = config["log_path"]
  86. LogFile = config["log_file"]
  87. LogDataPath = config["log_data_path"]
  88. LogDataFile = config["log_data_file"]
  89. BinLogPath = config["binlog_path"]
  90. BinLogFile = config["binlog_file"]
  91. ApiLogPath = config["apilog_path"]
  92. ApiLogFile = config["apilog_file"]
  93. logMaxDaysStr := config["log_max_day"]
  94. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  95. }
  96. }
  97. //http://webapi.brilliantstart.cn/api/
  98. //http://webapi.brilliantstart.cn/swagger/
  99. //http://139.196.122.219:8603/swagger/