config.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_DATA string
  13. MYSQL_URL_RDDP string
  14. REDIS_CACHE string //缓存地址
  15. Rc *cache.Cache //redis缓存
  16. Re error //redis错误
  17. )
  18. // 日志配置
  19. var (
  20. LogPath string //调用过程中的日志存放地址
  21. LogFile string
  22. BinLogPath string //数据库相关的日志存放地址
  23. BinLogFile string
  24. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  25. ApiLogFile string
  26. LogMaxDays int //日志最大保留天数
  27. )
  28. var (
  29. BusinessCode string //商家编码
  30. AppId string
  31. Secret string
  32. )
  33. // ES索引配置
  34. var (
  35. EsReportIndexName string //研报ES索引
  36. EsEnglishReportIndexName string //英文研报ES索引
  37. SmartReportIndexName string //智能研报ES索引
  38. )
  39. // ES配置
  40. var (
  41. ES_URL string // ES服务器地址
  42. ES_USERNAME string // ES账号
  43. ES_PASSWORD string // ES密码
  44. )
  45. // 内部配置
  46. var (
  47. EdbChartLibUrl string // 图库服务地址
  48. )
  49. func init() {
  50. tmpRunMode, err := web.AppConfig.String("run_mode")
  51. if err != nil {
  52. panic("配置文件读取run_mode错误 " + err.Error())
  53. }
  54. RunMode = tmpRunMode
  55. if RunMode == "" {
  56. localIp, err := GetLocalIP()
  57. fmt.Println("localIp:", localIp)
  58. if localIp == "10.0.0.123" {
  59. RunMode = "debug"
  60. } else {
  61. RunMode = "release"
  62. }
  63. configPath := `/home/code/config/eta_hub/conf/app.conf`
  64. err = web.LoadAppConfig("ini", configPath)
  65. if err != nil {
  66. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  67. }
  68. }
  69. config, err := web.AppConfig.GetSection(RunMode)
  70. if err != nil {
  71. panic("配置文件读取错误 " + err.Error())
  72. }
  73. beeLogger.Log.Info(RunMode + " 模式")
  74. MYSQL_URL = config["mysql_url"]
  75. MYSQL_URL_DATA = config["mysql_url_data"]
  76. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  77. REDIS_CACHE = config["beego_cache"]
  78. if len(REDIS_CACHE) <= 0 {
  79. panic(any("redis链接参数没有配置"))
  80. }
  81. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  82. if Re != nil {
  83. fmt.Println(Re)
  84. panic(any(Re))
  85. }
  86. //商家编码
  87. BusinessCode = config["business_code"]
  88. if BusinessCode == "" {
  89. panic("商家编码未配置,请先配置商家编码")
  90. }
  91. AppId = config["appid"]
  92. if AppId == "" {
  93. panic("appid未配置")
  94. }
  95. Secret = config["secret"]
  96. if Secret == "" {
  97. panic("secret未配置")
  98. }
  99. //日志配置
  100. {
  101. LogPath = config["log_path"]
  102. LogFile = config["log_file"]
  103. BinLogPath = config["binlog_path"]
  104. BinLogFile = config["binlog_file"]
  105. ApiLogPath = config["apilog_path"]
  106. ApiLogFile = config["apilog_file"]
  107. logMaxDaysStr := config["log_max_day"]
  108. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  109. }
  110. // ES 索引
  111. {
  112. EsReportIndexName = config["es_report_index_name"]
  113. EsEnglishReportIndexName = config["es_english_report_index_name"]
  114. SmartReportIndexName = config["es_smart_report_index_name"]
  115. }
  116. // ES配置
  117. {
  118. ES_URL = config["es_url"]
  119. ES_USERNAME = config["es_username"]
  120. ES_PASSWORD = config["es_password"]
  121. }
  122. // 内部配置
  123. {
  124. EdbChartLibUrl = config["edb_chart_lib_url"]
  125. }
  126. }