config.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. var (
  58. UseMongo bool // 是否使用mongo
  59. )
  60. func init() {
  61. tmpRunMode, err := web.AppConfig.String("run_mode")
  62. if err != nil {
  63. panic("配置文件读取run_mode错误 " + err.Error())
  64. }
  65. RunMode = tmpRunMode
  66. if RunMode == "" {
  67. localIp, err := GetLocalIP()
  68. fmt.Println("localIp:", localIp)
  69. if localIp == "10.0.0.123" {
  70. RunMode = "debug"
  71. } else {
  72. RunMode = "release"
  73. }
  74. configPath := `/home/code/config/eta_hub/conf/app.conf`
  75. err = web.LoadAppConfig("ini", configPath)
  76. if err != nil {
  77. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  78. }
  79. }
  80. config, err := web.AppConfig.GetSection(RunMode)
  81. if err != nil {
  82. panic("配置文件读取错误 " + err.Error())
  83. }
  84. beeLogger.Log.Info(RunMode + " 模式")
  85. MYSQL_URL = config["mysql_url"]
  86. MYSQL_URL_DATA = config["mysql_url_data"]
  87. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  88. // mongodb数据库连接配置
  89. MgoUrlData = config["mgo_url_data"]
  90. REDIS_CACHE = config["beego_cache"]
  91. if len(REDIS_CACHE) <= 0 {
  92. panic(any("redis链接参数没有配置"))
  93. }
  94. //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  95. //if Re != nil {
  96. // fmt.Println(Re)
  97. // panic(any(Re))
  98. //}
  99. // 初始化缓存
  100. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  101. if err != nil {
  102. fmt.Println("redis链接异常:", err)
  103. panic(any(Re))
  104. }
  105. Rc = redisClient
  106. //商家编码
  107. BusinessCode = config["business_code"]
  108. if BusinessCode == "" {
  109. panic("商家编码未配置,请先配置商家编码")
  110. }
  111. AppId = config["appid"]
  112. if AppId == "" {
  113. panic("appid未配置")
  114. }
  115. Secret = config["secret"]
  116. if Secret == "" {
  117. panic("secret未配置")
  118. }
  119. //日志配置
  120. {
  121. LogPath = config["log_path"]
  122. LogFile = config["log_file"]
  123. BinLogPath = config["binlog_path"]
  124. BinLogFile = config["binlog_file"]
  125. ApiLogPath = config["apilog_path"]
  126. ApiLogFile = config["apilog_file"]
  127. logMaxDaysStr := config["log_max_day"]
  128. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  129. }
  130. // ES 索引
  131. {
  132. EsReportIndexName = config["es_report_index_name"]
  133. EsEnglishReportIndexName = config["es_english_report_index_name"]
  134. SmartReportIndexName = config["es_smart_report_index_name"]
  135. }
  136. // ES配置
  137. {
  138. ES_URL = config["es_url"]
  139. ES_USERNAME = config["es_username"]
  140. ES_PASSWORD = config["es_password"]
  141. }
  142. // 内部配置
  143. {
  144. EdbChartLibUrl = config["edb_chart_lib_url"]
  145. // 公共指标库相关
  146. EDB_LIB_URL = config["edb_lib_url"]
  147. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  148. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  149. }
  150. }