config.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. var STATIC_DIR string
  58. // 对象存储客户端
  59. var (
  60. ObjectStorageClient string // 目前有oss minio,默认oss
  61. ResourceProxyUrl string
  62. RESOURCE_DIR string
  63. )
  64. // 阿里云配置
  65. var (
  66. Bucketname string
  67. Endpoint string
  68. Imghost string
  69. UploadDir string
  70. Upload_Audio_Dir string
  71. AccessKeyId string
  72. AccessKeySecret string
  73. )
  74. // 阿里云oss前端上传用
  75. var (
  76. AliStsScheme string
  77. RegionId string
  78. RoleArn string
  79. RoleSessionName string
  80. RAMAccessKeyId string
  81. RAMAccessKeySecret string
  82. STSTokenCacheKey string
  83. )
  84. // MinIo配置
  85. var (
  86. MinIoBucketname string
  87. MinIoEndpoint string
  88. MinIoBackEndpoint string
  89. MinIoImghost string
  90. MinIoUploadDir string
  91. MinIoUpload_Audio_Dir string
  92. MinIoAccessKeyId string
  93. MinIoAccessKeySecret string
  94. MinIoUseSSL string
  95. MinIoPort string
  96. MinIoRegion string
  97. MinIoFileDownloadHost string
  98. )
  99. // S3配置
  100. var (
  101. S3Endpoint string
  102. S3BackEndpoint string
  103. S3BucketName string
  104. S3UploadDir string
  105. S3AccessKeyId string
  106. S3AccessKeySecret string
  107. S3Host string
  108. S3Region string
  109. S3ForceStyle string
  110. S3EndpointPort string
  111. S3Protocol string
  112. S3DisableSSL string
  113. S3OpenAcl string
  114. )
  115. func init() {
  116. tmpRunMode, err := web.AppConfig.String("run_mode")
  117. if err != nil {
  118. panic("配置文件读取run_mode错误 " + err.Error())
  119. }
  120. RunMode = tmpRunMode
  121. fmt.Println("RunMode:", RunMode)
  122. if RunMode == "" {
  123. localIp, err := GetLocalIP()
  124. fmt.Println("localIp:", localIp)
  125. if localIp == "10.0.0.123" {
  126. RunMode = "debug"
  127. } else {
  128. RunMode = "release"
  129. }
  130. fmt.Println("RunMode:", RunMode)
  131. configPath := `/home/code/config/eta_forum_admin/conf/app.conf`
  132. fmt.Println("configPath:", configPath)
  133. err = web.LoadAppConfig("ini", configPath)
  134. if err != nil {
  135. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  136. }
  137. }
  138. config, err := web.AppConfig.GetSection(RunMode)
  139. if err != nil {
  140. panic("配置文件读取错误 " + err.Error())
  141. }
  142. beeLogger.Log.Info(RunMode + " 模式")
  143. // 项目中文名称
  144. appNameCn, err := web.AppConfig.String("app_name_cn")
  145. if err != nil {
  146. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  147. }
  148. APP_NAME_CN = appNameCn
  149. MYSQL_URL = config["mysql_url"]
  150. MYSQL_URL_WEEKLY_TRIAL = config["mysql_url_weekly_trial"]
  151. // mongodb数据库连接配置
  152. MgoUrlData = config["mgo_url_data"]
  153. //日志配置
  154. {
  155. LogPath = config["log_path"]
  156. LogFile = config["log_file"]
  157. LogDataPath = config["log_data_path"]
  158. LogDataFile = config["log_data_file"]
  159. BinLogPath = config["binlog_path"]
  160. BinLogFile = config["binlog_file"]
  161. ApiLogPath = config["apilog_path"]
  162. ApiLogFile = config["apilog_file"]
  163. logMaxDaysStr := config["log_max_day"]
  164. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  165. }
  166. // 接口返回加密KEY
  167. DesKey = config["des_key"]
  168. {
  169. // 报警服务地址
  170. AlarmMsgUrl = config["alarm_msg_url"]
  171. }
  172. // 初始化缓存
  173. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  174. if err != nil {
  175. fmt.Println("redis链接异常:", err)
  176. panic(any(Re))
  177. }
  178. Rc = redisClient
  179. // ES配置
  180. {
  181. ES_URL = config["es_url"]
  182. ES_USERNAME = config["es_username"]
  183. ES_PASSWORD = config["es_password"]
  184. }
  185. // 初始化ES
  186. initEs()
  187. // ES 索引
  188. {
  189. DATA_INDEX_NAME = config["data_index_name"]
  190. CHART_INDEX_NAME = config["chart_index_name"]
  191. }
  192. // CRM-ETA服务地址
  193. CrmEtaServerUrl = "http://127.0.0.1:8708"
  194. if config["crm_eta_server_url"] != "" {
  195. CrmEtaServerUrl = config["crm_eta_server_url"]
  196. }
  197. CrmEtaAuthorization = "NIi1RbEmH0C2rksXtPGDPBBgRgTZY87Q"
  198. if config["crm_eta_authorization"] != "" {
  199. CrmEtaAuthorization = config["crm_eta_authorization"]
  200. }
  201. // 静态文件目录
  202. STATIC_DIR = config["static_dir"]
  203. if STATIC_DIR == "" {
  204. // 静态文件目录
  205. STATIC_DIR = "static"
  206. }
  207. {
  208. // 对象存储客户端
  209. ObjectStorageClient = config["object_storage_client"]
  210. // OSS相关
  211. {
  212. Endpoint = config["endpoint"]
  213. Bucketname = config["bucket_name"]
  214. Imghost = config["img_host"]
  215. UploadDir = config["upload_dir"]
  216. Upload_Audio_Dir = config["upload_audio_dir"]
  217. AccessKeyId = config["access_key_id"]
  218. AccessKeySecret = config["access_key_secret"]
  219. }
  220. // OSS相关(前端使用)
  221. {
  222. AliStsScheme = config["ali_sts_scheme"]
  223. RegionId = config["region_id"]
  224. RoleArn = config["role_arn"]
  225. RoleSessionName = config["role_session_name"]
  226. RAMAccessKeyId = config["ram_access_key_id"]
  227. RAMAccessKeySecret = config["ram_access_key_secret"]
  228. STSTokenCacheKey = config["sts_token_cache_key"]
  229. }
  230. // MinIo相关
  231. {
  232. MinIoEndpoint = config["minio_endpoint"]
  233. MinIoBackEndpoint = config["minio_back_endpoint"]
  234. MinIoBucketname = config["minio_bucket_name"]
  235. MinIoImghost = config["minio_img_host"]
  236. MinIoUploadDir = config["minio_upload_dir"]
  237. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  238. MinIoAccessKeyId = config["minio_access_key_id"]
  239. MinIoAccessKeySecret = config["minio_access_key_secret"]
  240. MinIoUseSSL = config["minio_use_ssl"]
  241. MinIoPort = config["minio_port"]
  242. MinIoRegion = config["minio_region"]
  243. MinIoFileDownloadHost = config["minio_file_download_host"]
  244. }
  245. // S3-OSS相关
  246. {
  247. S3Endpoint = config["s3_endpoint"]
  248. S3BackEndpoint = config["s3_back_endpoint"]
  249. S3BucketName = config["s3_bucket_name"]
  250. S3Host = config["s3_host"]
  251. S3AccessKeyId = config["s3_access_key_id"]
  252. S3AccessKeySecret = config["s3_access_key_secret"]
  253. S3UploadDir = config["s3_upload_dir"]
  254. S3Region = config["s3_region"]
  255. S3ForceStyle = config["s3_force_style"]
  256. S3EndpointPort = config["s3_endpoint_port"]
  257. S3Protocol = config["s3_protocol"]
  258. S3DisableSSL = config["s3_disable_ssl"]
  259. S3OpenAcl = config["s3_open_acl"]
  260. }
  261. }
  262. }
  263. //修改接口文档
  264. //http://8.136.199.33:8300/swagger/