config.go 3.9 KB

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