config.go 7.4 KB

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