config.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/server/web"
  5. "github.com/rdlucklib/rdluck_tools/cache"
  6. )
  7. var (
  8. RunMode string //运行模式
  9. MYSQL_URL string //数据库连接
  10. MYSQL_URL_RDDP string //数据库连接
  11. MYSQL_URL_TACTICS 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. func init() {
  26. tmpRunMode, err := web.AppConfig.String("run_mode")
  27. if err != nil {
  28. panic("配置文件读取run_mode错误 " + err.Error())
  29. }
  30. RunMode = tmpRunMode
  31. if RunMode == "" {
  32. localIp, err := GetLocalIP()
  33. fmt.Println("localIp:", localIp)
  34. if localIp == "10.0.0.123" {
  35. RunMode = "debug"
  36. } else {
  37. RunMode = "release"
  38. }
  39. configPath := `/home/code/config/hongze_clpt/conf/app.conf`
  40. err = web.LoadAppConfig("ini", configPath)
  41. if err != nil {
  42. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  43. }
  44. }
  45. config, err := web.AppConfig.GetSection(RunMode)
  46. if err != nil {
  47. panic("配置文件读取错误 " + err.Error())
  48. }
  49. fmt.Println(RunMode + " 模式")
  50. MYSQL_URL = config["mysql_url"]
  51. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  52. REDIS_CACHE = config["beego_cache"]
  53. if len(REDIS_CACHE) <= 0 {
  54. panic("redis链接参数没有配置")
  55. }
  56. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  57. if Re != nil {
  58. fmt.Println(Re)
  59. panic(Re)
  60. }
  61. if RunMode == "release" {
  62. WxPublicAppId = "wxb7cb8a15abad5b8e" //查研观向小助手
  63. WxPublicAppSecret = "f425ba2863084249722af1e2a5cfffd3" //查研观向小助手
  64. } else {
  65. WxPublicAppId = "wx9b5d7291e581233a" //弘则投研公众号 开发者ID(AppID)
  66. WxPublicAppSecret = "f4d52e34021eee262dce9682b31f8861" //弘则投研公众号秘钥
  67. }
  68. HeadimgurlDefault = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202202/20220225/XFBBOUmDC5AXkfxnHiuqKpPtoofH.png"
  69. }
  70. //http://webapi.brilliantstart.cn/api/
  71. //http://webapi.brilliantstart.cn/swagger/
  72. //http://139.196.122.219:8603/swagger/