config.go 7.3 KB

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