config.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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_DATA string
  12. MYSQL_URL_EDB string
  13. REDIS_CACHE string //缓存地址
  14. Rc *cache.Cache //redis缓存
  15. Re error //redis错误
  16. )
  17. func init() {
  18. tmpRunMode, err := web.AppConfig.String("run_mode")
  19. if err != nil {
  20. panic("配置文件读取run_mode错误 " + err.Error())
  21. }
  22. RunMode = tmpRunMode
  23. if RunMode == "" {
  24. RunMode = "release"
  25. configPath := `/home/code/config/hongze_chart_lib/conf/app.conf`
  26. err := web.LoadAppConfig("ini", configPath)
  27. if err != nil {
  28. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  29. }
  30. }
  31. config, err := web.AppConfig.GetSection(RunMode)
  32. if err != nil {
  33. panic("配置文件读取错误 " + err.Error())
  34. }
  35. beeLogger.Log.Info(RunMode + " 模式")
  36. MYSQL_URL = config["mysql_url"]
  37. MYSQL_URL_DATA = config["mysql_url_data"]
  38. MYSQL_URL_EDB = config["mysql_url_edb"]
  39. REDIS_CACHE = config["beego_cache"]
  40. if len(REDIS_CACHE) <= 0 {
  41. panic("redis链接参数没有配置")
  42. }
  43. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  44. if Re != nil {
  45. fmt.Println(Re)
  46. panic(Re)
  47. }
  48. if RunMode == "release" {
  49. //同花顺,万得接口服务地址(阿里云windows服务器地址;内网地址)
  50. Hz_Server_Data_Url = "http://172.19.173.231:7000/"
  51. } else {
  52. //同花顺,万得接口服务地址(阿里云windows服务器地址;外网地址)
  53. Hz_Server_Data_Url = "http://139.196.136.213:7000/"
  54. }
  55. }
  56. //http://8.136.199.33:8608/swagger/
  57. //http://8.136.199.33:8608/v1