config.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. var (
  58. UseMongo bool // 是否使用mongo
  59. )
  60. // AlarmMsgUrl 报警服务地址
  61. var AlarmMsgUrl string
  62. func init() {
  63. tmpRunMode, err := web.AppConfig.String("run_mode")
  64. if err != nil {
  65. panic("配置文件读取run_mode错误 " + err.Error())
  66. }
  67. RunMode = tmpRunMode
  68. fmt.Println("RunMode:", RunMode)
  69. if RunMode == "" {
  70. localIp, err := GetLocalIP()
  71. fmt.Println("localIp:", localIp)
  72. if localIp == "10.0.0.123" {
  73. RunMode = "debug"
  74. } else {
  75. RunMode = "release"
  76. }
  77. fmt.Println("RunMode:", RunMode)
  78. configPath := `/home/code/config/eta_forum_task/conf/app.conf`
  79. fmt.Println("configPath:", configPath)
  80. err = web.LoadAppConfig("ini", configPath)
  81. if err != nil {
  82. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  83. }
  84. }
  85. config, err := web.AppConfig.GetSection(RunMode)
  86. if err != nil {
  87. panic("配置文件读取错误 " + err.Error())
  88. }
  89. beeLogger.Log.Info(RunMode + " 模式")
  90. // 项目中文名称
  91. appNameCn, err := web.AppConfig.String("app_name_cn")
  92. if err != nil {
  93. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  94. }
  95. APP_NAME_CN = appNameCn
  96. MYSQL_URL = config["mysql_url"]
  97. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  98. MYSQL_URL_EDB = config["mysql_url_edb"]
  99. MYSQL_URL_DATA = config["mysql_url_data"]
  100. MYSQL_URL_GL = config["mysql_url_gl"]
  101. // mongodb数据库连接配置
  102. MgoUrlData = config["mgo_url_data"]
  103. //日志配置
  104. {
  105. LogPath = config["log_path"]
  106. LogFile = config["log_file"]
  107. LogDataPath = config["log_data_path"]
  108. LogDataFile = config["log_data_file"]
  109. BinLogPath = config["binlog_path"]
  110. BinLogFile = config["binlog_file"]
  111. ApiLogPath = config["apilog_path"]
  112. ApiLogFile = config["apilog_file"]
  113. logMaxDaysStr := config["log_max_day"]
  114. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  115. }
  116. {
  117. // 报警服务地址
  118. AlarmMsgUrl = config["alarm_msg_url"]
  119. }
  120. // 初始化缓存
  121. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  122. if err != nil {
  123. fmt.Println("redis链接异常:", err)
  124. panic(any(Re))
  125. }
  126. Rc = redisClient
  127. // ES配置
  128. {
  129. ES_URL = config["es_url"]
  130. ES_USERNAME = config["es_username"]
  131. ES_PASSWORD = config["es_password"]
  132. }
  133. // 初始化ES
  134. initEs()
  135. // ES 索引
  136. {
  137. DATA_INDEX_NAME = config["data_index_name"]
  138. CHART_INDEX_NAME = config["chart_index_name"]
  139. }
  140. // eta_forum_hub ETA社区桥接服务地址
  141. {
  142. ETA_FORUM_HUB_URL = config["eta_forum_hub_url"]
  143. ETA_FORUM_HUB_NAME_EN = config["eta_forum_hub_name_en"]
  144. ETA_FORUM_HUB_MD5_KEY = config["eta_forum_hub_md5_key"]
  145. }
  146. }
  147. //修改接口文档
  148. //http://8.136.199.33:8300/swagger/