config.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "go.mongodb.org/mongo-driver/mongo"
  7. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. APP_NAME_CN string
  12. MYSQL_URL string //数据库连接
  13. MYSQL_URL_WEEKLY_TRIAL string //eta试用数据库
  14. Re error //redis错误
  15. Rc RedisClient //redis缓存
  16. MgoUrlData string // mongodb数据库连接配置
  17. MgoDataCli *mongo.Client // mongodb客户端连接
  18. MgoDataDbName string // mongodb指标数据的库名
  19. )
  20. // ES配置
  21. var (
  22. ES_URL string // ES服务器地址
  23. ES_USERNAME string // ES账号
  24. ES_PASSWORD string // ES密码
  25. )
  26. // ES索引配置
  27. var (
  28. DATA_INDEX_NAME string //数据指标库索引
  29. CHART_INDEX_NAME string //研究图库索引
  30. )
  31. // 弘则
  32. const (
  33. APPID = "SJCrpOPvagscPxEv"
  34. SECRET = "gLLjT72uFHQZEFtaFCuoZegD1z2ezfyX"
  35. )
  36. // 日志配置
  37. var (
  38. LogPath string //调用过程中的日志存放地址
  39. LogFile string
  40. LogDataPath string //调用过程中图表相关的日志存放地址
  41. LogDataFile string
  42. BinLogPath string //数据库相关的日志存放地址
  43. BinLogFile string
  44. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  45. ApiLogFile string
  46. LogMaxDays int //日志最大保留天数
  47. )
  48. // 基础配置
  49. var (
  50. DesKey string // 接口返回加密KEY
  51. )
  52. // AlarmMsgUrl 报警服务地址
  53. var AlarmMsgUrl string
  54. // CrmEtaServerUrl CRM-ETA服务地址
  55. var CrmEtaServerUrl string
  56. var CrmEtaAuthorization string
  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. fmt.Println("RunMode:", RunMode)
  64. if RunMode == "" {
  65. localIp, err := GetLocalIP()
  66. fmt.Println("localIp:", localIp)
  67. if localIp == "10.0.0.123" {
  68. RunMode = "debug"
  69. } else {
  70. RunMode = "release"
  71. }
  72. fmt.Println("RunMode:", RunMode)
  73. configPath := `/home/code/config/eta_forum_admin/conf/app.conf`
  74. fmt.Println("configPath:", configPath)
  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. // 项目中文名称
  86. appNameCn, err := web.AppConfig.String("app_name_cn")
  87. if err != nil {
  88. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  89. }
  90. APP_NAME_CN = appNameCn
  91. MYSQL_URL = config["mysql_url"]
  92. MYSQL_URL_WEEKLY_TRIAL = config["mysql_url_weekly_trial"]
  93. // mongodb数据库连接配置
  94. MgoUrlData = config["mgo_url_data"]
  95. //日志配置
  96. {
  97. LogPath = config["log_path"]
  98. LogFile = config["log_file"]
  99. LogDataPath = config["log_data_path"]
  100. LogDataFile = config["log_data_file"]
  101. BinLogPath = config["binlog_path"]
  102. BinLogFile = config["binlog_file"]
  103. ApiLogPath = config["apilog_path"]
  104. ApiLogFile = config["apilog_file"]
  105. logMaxDaysStr := config["log_max_day"]
  106. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  107. }
  108. // 接口返回加密KEY
  109. DesKey = config["des_key"]
  110. {
  111. // 报警服务地址
  112. AlarmMsgUrl = config["alarm_msg_url"]
  113. }
  114. // 初始化缓存
  115. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  116. if err != nil {
  117. fmt.Println("redis链接异常:", err)
  118. panic(any(Re))
  119. }
  120. Rc = redisClient
  121. // ES配置
  122. {
  123. ES_URL = config["es_url"]
  124. ES_USERNAME = config["es_username"]
  125. ES_PASSWORD = config["es_password"]
  126. }
  127. // 初始化ES
  128. initEs()
  129. // ES 索引
  130. {
  131. DATA_INDEX_NAME = config["data_index_name"]
  132. CHART_INDEX_NAME = config["chart_index_name"]
  133. }
  134. // CRM-ETA服务地址
  135. CrmEtaServerUrl = "http://127.0.0.1:8708"
  136. if config["crm_eta_server_url"] != "" {
  137. CrmEtaServerUrl = config["crm_eta_server_url"]
  138. }
  139. CrmEtaAuthorization = "NIi1RbEmH0C2rksXtPGDPBBgRgTZY87Q"
  140. if config["crm_eta_authorization"] != "" {
  141. CrmEtaAuthorization = config["crm_eta_authorization"]
  142. }
  143. }
  144. //修改接口文档
  145. //http://8.136.199.33:8300/swagger/