config.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. APP_NAME_CN string
  12. MYSQL_URL string //数据库连接
  13. MYSQL_URL_RDDP string //数据库连接
  14. MYSQL_URL_EDB string
  15. MYSQL_URL_DATA string
  16. MYSQL_URL_GL string
  17. Re error //redis错误
  18. Rc RedisClient //redis缓存
  19. MgoUrlData string // mongodb数据库连接配置
  20. MgoDataCli *qmgo.Client // mongodb客户端连接
  21. MgoDataDbName string // mongodb指标数据的库名
  22. )
  23. // ES配置
  24. var (
  25. ES_URL string // ES服务器地址
  26. ES_USERNAME string // ES账号
  27. ES_PASSWORD string // ES密码
  28. )
  29. // ES索引配置
  30. var (
  31. DATA_INDEX_NAME string //数据指标库索引
  32. CHART_INDEX_NAME string //研究图库索引
  33. )
  34. // 弘则
  35. const (
  36. APPID = "SJCrpOPvagscPxEv"
  37. SECRET = "gLLjT72uFHQZEFtaFCuoZegD1z2ezfyX"
  38. )
  39. // 日志配置
  40. var (
  41. LogPath string //调用过程中的日志存放地址
  42. LogFile string
  43. LogDataPath string //调用过程中图表相关的日志存放地址
  44. LogDataFile string
  45. BinLogPath string //数据库相关的日志存放地址
  46. BinLogFile string
  47. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  48. ApiLogFile string
  49. LogMaxDays int //日志最大保留天数
  50. )
  51. // eta_forum_hub ETA社区桥接服务地址
  52. var (
  53. ETA_FORUM_HUB_URL string
  54. ETA_FORUM_HUB_NAME_EN string
  55. ETA_FORUM_HUB_MD5_KEY string
  56. )
  57. // AlarmMsgUrl 报警服务地址
  58. var AlarmMsgUrl string
  59. func init() {
  60. tmpRunMode, err := web.AppConfig.String("run_mode")
  61. if err != nil {
  62. panic("配置文件读取run_mode错误 " + err.Error())
  63. }
  64. RunMode = tmpRunMode
  65. fmt.Println("RunMode:", RunMode)
  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. fmt.Println("RunMode:", RunMode)
  75. configPath := `/home/code/config/eta_forum_task/conf/app.conf`
  76. fmt.Println("configPath:", configPath)
  77. err = web.LoadAppConfig("ini", configPath)
  78. if err != nil {
  79. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  80. }
  81. }
  82. config, err := web.AppConfig.GetSection(RunMode)
  83. if err != nil {
  84. panic("配置文件读取错误 " + err.Error())
  85. }
  86. beeLogger.Log.Info(RunMode + " 模式")
  87. // 项目中文名称
  88. appNameCn, err := web.AppConfig.String("app_name_cn")
  89. if err != nil {
  90. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  91. }
  92. APP_NAME_CN = appNameCn
  93. MYSQL_URL = config["mysql_url"]
  94. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  95. MYSQL_URL_EDB = config["mysql_url_edb"]
  96. MYSQL_URL_DATA = config["mysql_url_data"]
  97. MYSQL_URL_GL = config["mysql_url_gl"]
  98. // mongodb数据库连接配置
  99. MgoUrlData = config["mgo_url_data"]
  100. //日志配置
  101. {
  102. LogPath = config["log_path"]
  103. LogFile = config["log_file"]
  104. LogDataPath = config["log_data_path"]
  105. LogDataFile = config["log_data_file"]
  106. BinLogPath = config["binlog_path"]
  107. BinLogFile = config["binlog_file"]
  108. ApiLogPath = config["apilog_path"]
  109. ApiLogFile = config["apilog_file"]
  110. logMaxDaysStr := config["log_max_day"]
  111. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  112. }
  113. {
  114. // 报警服务地址
  115. AlarmMsgUrl = config["alarm_msg_url"]
  116. }
  117. // 初始化缓存
  118. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  119. if err != nil {
  120. fmt.Println("redis链接异常:", err)
  121. panic(any(Re))
  122. }
  123. Rc = redisClient
  124. // ES配置
  125. {
  126. ES_URL = config["es_url"]
  127. ES_USERNAME = config["es_username"]
  128. ES_PASSWORD = config["es_password"]
  129. }
  130. // 初始化ES
  131. initEs()
  132. // ES 索引
  133. {
  134. DATA_INDEX_NAME = config["data_index_name"]
  135. CHART_INDEX_NAME = config["chart_index_name"]
  136. }
  137. // eta_forum_hub ETA社区桥接服务地址
  138. {
  139. ETA_FORUM_HUB_URL = config["eta_forum_hub_url"]
  140. ETA_FORUM_HUB_NAME_EN = config["eta_forum_hub_name_en"]
  141. ETA_FORUM_HUB_MD5_KEY = config["eta_forum_hub_md5_key"]
  142. }
  143. }
  144. //修改接口文档
  145. //http://8.136.199.33:8300/swagger/