config.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. package utils
  2. import (
  3. "errors"
  4. "fmt"
  5. "strconv"
  6. beeLogger "github.com/beego/bee/v2/logger"
  7. "github.com/beego/beego/v2/server/web"
  8. "github.com/qiniu/qmgo"
  9. "github.com/spf13/viper"
  10. )
  11. var (
  12. RunMode string //运行模式
  13. MYSQL_URL string //数据库连接
  14. MYSQL_URL_RDDP string //数据库连接
  15. MYSQL_URL_EDB string
  16. MYSQL_URL_DATA string
  17. MYSQL_URL_GL string
  18. MYSQL_LOG_URL string
  19. MYSQL_WEEKLY_URL string //用户主库
  20. MYSQL_AI_URL string //ETA-AI 数据库
  21. MgoUrlData string // mongodb数据库连接配置
  22. REDIS_CACHE string //缓存地址
  23. Re error //redis错误
  24. Rc RedisClient //redis缓存
  25. MgoDataCli *qmgo.Client // mongodb客户端连接
  26. MgoDataDbName string // mongodb指标数据的库名
  27. )
  28. var (
  29. STATIC_DIR string
  30. DesKey string // 接口返回加密KEY
  31. APPNAME string //项目中文名称
  32. EmailSendToUsers string // 邮件提醒人员
  33. JhGnAppKey string // 聚合短信,国内AppKey
  34. JhGjAppKey string // 聚合短信,国际AppKey
  35. ResourceProxyUrl string // 代理资源地址
  36. RESOURCE_DIR string
  37. )
  38. var (
  39. ES_URL string // ES服务器地址
  40. ES_USERNAME string // ES账号
  41. ES_PASSWORD string // ES密码
  42. )
  43. var (
  44. EDB_LIB_URL string
  45. APP_EDB_LIB_NAME_EN string
  46. EDB_LIB_Md5_KEY string
  47. PublicChartHost string
  48. MySteelPostUrl string
  49. SendWxTemplateMsgUrl string
  50. SendTemplateMsgAuthorization string
  51. HandleVideoDecibelUrl string
  52. Ppt2ImageUrl string
  53. HongzeOpenApiHost string
  54. EnglishShareUrl string
  55. EnPolicyReportUrl string
  56. GoogleTranslateUrl string
  57. AlarmMsgUrl string
  58. ChatUrl string
  59. EtaBridgeUrl string // 桥接服务地址
  60. EtaBridgeAppNameEn string // 桥接服务英文名称-鉴权用
  61. EtaBridgeMd5Key string // 桥接服务Md5密钥-鉴权用
  62. EtaBridgeDesKey string // 桥接服务Des密钥-解密数据用
  63. EtaBridgeLoginUrl string // 第三方登录鉴权接口地址
  64. EtaBridgeLogoutUrl string // 第三方登出接口地址
  65. ETAMiniBridgeUrl string // 桥接服务地址
  66. ETA_MINI_APPID string // 桥接服务-鉴权用
  67. ETA_MINI_APP_SECRET string // 桥接服务-鉴权用
  68. )
  69. var (
  70. WxId string //微信原始ID
  71. WxAppId string // 公众号appid
  72. WxAppSecret string // 公众号秘钥
  73. TemplateIdByProduct string //产品运行报告通知-模板ID
  74. WxYbAppId string // 研报小程序appid
  75. WxYbId string // 研报小程序微信原始ID
  76. WxYbAppSecret string // 研报小程序秘钥
  77. WxYbPlatform int //国能研报来源
  78. )
  79. var (
  80. DATA_INDEX_NAME string //数据指标库索引
  81. CHART_INDEX_NAME string //研究图库索引
  82. EsReportIndexName string //研报ES索引
  83. EsEnglishReportIndexName string //英文研报ES索引
  84. MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
  85. EsSemanticAnalysisDocIndexName string //ES语义分析文档索引名
  86. SmartReportIndexName string //智能研报ES索引
  87. )
  88. var (
  89. XfHostUrl string // 科大讯飞--语音合成
  90. )
  91. var (
  92. ObjectStorageClient string // 目前有oss minio,默认oss
  93. PptUpdateApi string //ppt 通过后端接口的方式上传
  94. )
  95. var (
  96. Bucketname string
  97. Endpoint string
  98. Imghost string
  99. UploadDir string
  100. Upload_Audio_Dir string
  101. AccessKeyId string
  102. AccessKeySecret string
  103. )
  104. var (
  105. AliStsScheme string
  106. RegionId string
  107. RoleArn string
  108. RoleSessionName string
  109. RAMAccessKeyId string
  110. RAMAccessKeySecret string
  111. STSTokenCacheKey string
  112. )
  113. var (
  114. AliyunEmailAccountName string
  115. AliyunEmailAccessKeyId string
  116. AliyunEmailAccessKeySecret string
  117. AliyunEmailReplyAddress string
  118. AliyunEmailReplyAddressAlias string
  119. )
  120. var (
  121. TencentSDKSecretId string // 腾讯云主账号SecretId
  122. TencentSDKSecretKey string // 腾讯云主账号SecretKey
  123. TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
  124. TencentEmailTemplateID uint64 // 云邮件模板ID
  125. )
  126. var LibreOfficePath string
  127. var (
  128. CrmEtaServerUrl string
  129. CrmEtaServerDes3Key string
  130. )
  131. var (
  132. ETA_FORUM_HUB_URL string
  133. ETA_FORUM_HUB_NAME_EN string
  134. ETA_FORUM_HUB_MD5_KEY string
  135. )
  136. var BusinessCode string
  137. var (
  138. LogPath string //调用过程中的日志存放地址
  139. LogFile string
  140. LogDataPath string //调用过程中图表相关的日志存放地址
  141. LogDataFile string
  142. BinLogPath string //数据库相关的日志存放地址
  143. BinLogFile string
  144. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  145. ApiLogFile string
  146. LogMaxDays int //日志最大保留天数
  147. )
  148. var (
  149. MinIoBucketname string
  150. MinIoEndpoint string
  151. MinIoBackEndpoint string
  152. MinIoImghost string
  153. MinIoUploadDir string
  154. MinIoUpload_Audio_Dir string
  155. MinIoAccessKeyId string
  156. MinIoAccessKeySecret string
  157. MinIoUseSSL string
  158. MinIoPort string
  159. MinIoRegion string
  160. )
  161. var PythonUrlReport2Img string
  162. var EtaAiUrl string
  163. var (
  164. EtaAppid string
  165. EtaSecret string
  166. )
  167. var (
  168. S3Endpoint string
  169. S3BackEndpoint string
  170. S3BucketName string
  171. S3UploadDir string
  172. S3AccessKeyId string
  173. S3AccessKeySecret string
  174. S3Host string
  175. S3Region string
  176. S3ForceStyle string
  177. S3EndpointPort string
  178. S3Protocol string
  179. S3DisableSSL string
  180. S3OpenAcl string
  181. )
  182. var (
  183. ChromePath string // chrome浏览器地址
  184. )
  185. var (
  186. ErrMsgConfigFile string
  187. )
  188. var (
  189. ViperConfig *viper.Viper
  190. )
  191. var (
  192. UseMongo bool // 是否使用mongo
  193. )
  194. func init() {
  195. tmpRunMode, err := web.AppConfig.String("run_mode")
  196. if err != nil {
  197. panic(any("配置文件读取run_mode错误 " + err.Error()))
  198. }
  199. RunMode = tmpRunMode
  200. if RunMode == "" {
  201. configPath := `/home/code/config/eta_gn/eta_api/conf/app.conf`
  202. fmt.Println("configPath:", configPath)
  203. err = web.LoadAppConfig("ini", configPath)
  204. if err != nil {
  205. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  206. }
  207. tmpRunMode, err = web.AppConfig.String("run_mode")
  208. if err != nil {
  209. panic(any("配置文件读取run_mode错误 " + err.Error()))
  210. }
  211. RunMode = tmpRunMode
  212. }
  213. fmt.Println("RunMode:", RunMode)
  214. config, err := web.AppConfig.GetSection(RunMode)
  215. if err != nil {
  216. panic(any("配置文件读取错误 " + err.Error()))
  217. }
  218. beeLogger.Log.Info(RunMode + " 模式")
  219. MYSQL_URL = config["mysql_url"]
  220. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  221. MYSQL_URL_EDB = config["mysql_url_edb"]
  222. MYSQL_URL_DATA = config["mysql_url_data"]
  223. MYSQL_URL_GL = config["mysql_url_gl"]
  224. MYSQL_LOG_URL = config["mysql_url_log"]
  225. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  226. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  227. MYSQL_AI_URL = config["mysql_url_ai"]
  228. MgoUrlData = config["mgo_url_data"]
  229. REDIS_CACHE = config["beego_cache"]
  230. if len(REDIS_CACHE) <= 0 {
  231. panic(any("redis链接参数没有配置"))
  232. }
  233. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  234. if err != nil {
  235. fmt.Println("redis链接异常:", err)
  236. panic(any(Re))
  237. }
  238. Rc = redisClient
  239. appNameCn, err := web.AppConfig.String("app_name_cn")
  240. if err != nil {
  241. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  242. }
  243. APPNAME = appNameCn
  244. DesKey = config["des_key"]
  245. EmailSendToUsers = config["email_send_to_users"]
  246. JhGnAppKey = config["jh_gn_app_key"]
  247. JhGjAppKey = config["jh_gj_app_key"]
  248. Ppt2ImageUrl = config["ppt2_image_url"]
  249. STATIC_DIR = config["static_dir"]
  250. ResourceProxyUrl = config["resource_proxy_url"]
  251. RESOURCE_DIR = config["resource_dir"]
  252. if RESOURCE_DIR == "" {
  253. RESOURCE_DIR = "eta_gn/"
  254. }
  255. {
  256. EDB_LIB_URL = config["edb_lib_url"]
  257. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  258. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  259. PublicChartHost = config["public_chart_host"]
  260. MySteelPostUrl = config["mysteel_post_url"]
  261. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  262. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  263. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  264. HongzeOpenApiHost = config["hongze_open_api_host"]
  265. EnglishShareUrl = config["english_share_url"]
  266. EnPolicyReportUrl = config["en_policy_report_url"]
  267. GoogleTranslateUrl = config["google_translate_url"]
  268. AlarmMsgUrl = config["alarm_msg_url"]
  269. ChatUrl = config["chat_url"]
  270. EtaBridgeUrl = config["eta_bridge_url"] // 桥接服务地址
  271. EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
  272. EtaBridgeMd5Key = config["eta_bridge_md5_key"] // 桥接服务Md5密钥-鉴权用
  273. EtaBridgeDesKey = config["eta_bridge_des_key"] // 桥接服务Des密钥-解密数据用
  274. EtaBridgeLoginUrl = config["eta_bridge_login_url"] // eta桥接服务-登录接口地址
  275. EtaBridgeLogoutUrl = config["eta_bridge_logout_url"] // eta桥接服务-登出接口地址
  276. }
  277. {
  278. LogPath = config["log_path"]
  279. LogFile = config["log_file"]
  280. LogDataPath = config["log_data_path"]
  281. LogDataFile = config["log_data_file"]
  282. BinLogPath = config["binlog_path"]
  283. BinLogFile = config["binlog_file"]
  284. ApiLogPath = config["apilog_path"]
  285. ApiLogFile = config["apilog_file"]
  286. logMaxDaysStr := config["log_max_day"]
  287. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  288. }
  289. {
  290. ES_URL = config["es_url"]
  291. ES_USERNAME = config["es_username"]
  292. ES_PASSWORD = config["es_password"]
  293. }
  294. {
  295. WxAppId = config["wx_appid"]
  296. WxAppSecret = config["wx_app_secret"]
  297. WxId = config["wx_id"]
  298. TemplateIdByProduct = config["template_id_by_product"]
  299. WxYbAppId = config["wx_yb_appid"] //国能研报小程序
  300. WxYbId = config["wx_yb_id"] // 研报小程序微信原始ID
  301. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  302. wxYbPlatformStr := config["wx_yb_platform"]
  303. if wxYbPlatformStr != `` {
  304. WxYbPlatform, err = strconv.Atoi(wxYbPlatformStr) //国能研报来源
  305. if err != nil {
  306. panic(any("配置文件读取wx_yb_platform错误 " + err.Error()))
  307. }
  308. }
  309. }
  310. ObjectStorageClient = config["object_storage_client"]
  311. PptUpdateApi = config["ppt_update_api"]
  312. {
  313. Endpoint = config["endpoint"]
  314. Bucketname = config["bucket_name"]
  315. Imghost = config["img_host"]
  316. UploadDir = config["upload_dir"]
  317. Upload_Audio_Dir = config["upload_audio_dir"]
  318. AccessKeyId = config["access_key_id"]
  319. AccessKeySecret = config["access_key_secret"]
  320. }
  321. {
  322. AliStsScheme = config["ali_sts_scheme"]
  323. RegionId = config["region_id"]
  324. RoleArn = config["role_arn"]
  325. RoleSessionName = config["role_session_name"]
  326. RAMAccessKeyId = config["ram_access_key_id"]
  327. RAMAccessKeySecret = config["ram_access_key_secret"]
  328. STSTokenCacheKey = config["sts_token_cache_key"]
  329. }
  330. {
  331. AliyunEmailAccountName = config["aliyun_email_account_name"]
  332. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  333. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  334. AliyunEmailReplyAddress = config["aliyun_email_reply_address"]
  335. AliyunEmailReplyAddressAlias = config["aliyun_email_reply_address_alias"]
  336. }
  337. {
  338. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  339. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  340. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  341. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  342. if tencentEmailTemplateIDtr != `` {
  343. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //国能研报来源
  344. if err != nil {
  345. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  346. }
  347. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  348. }
  349. }
  350. {
  351. XfHostUrl = config["xf_host_url"]
  352. }
  353. {
  354. DATA_INDEX_NAME = config["data_index_name"]
  355. CHART_INDEX_NAME = config["chart_index_name"]
  356. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  357. EsReportIndexName = config["es_report_index_name"]
  358. EsEnglishReportIndexName = config["es_english_report_index_name"]
  359. EsSemanticAnalysisDocIndexName = config["es_semantic_analysis_doc_index_name"]
  360. SmartReportIndexName = config["es_smart_report_index_name"]
  361. }
  362. CrmEtaServerUrl = config["crm_eta_server_url"]
  363. CrmEtaServerDes3Key = config["crm_eta_server_des3_key"]
  364. LibreOfficePath = config["libre_office_path"]
  365. {
  366. ETA_FORUM_HUB_URL = config["eta_forum_hub_url"]
  367. ETA_FORUM_HUB_NAME_EN = config["eta_forum_hub_name_en"]
  368. ETA_FORUM_HUB_MD5_KEY = config["eta_forum_hub_md5_key"]
  369. }
  370. BusinessCode = config["business_code"]
  371. {
  372. ETAMiniBridgeUrl = config["eta_mini_bridge_url"]
  373. ETA_MINI_APPID = config["eta_mini_bridge_appid"] // 桥接服务-鉴权用
  374. ETA_MINI_APP_SECRET = config["eta_mini_bridge_secret"] // 桥接服务-鉴权用
  375. }
  376. {
  377. MinIoEndpoint = config["minio_endpoint"]
  378. MinIoBackEndpoint = config["minio_back_endpoint"]
  379. MinIoBucketname = config["minio_bucket_name"]
  380. MinIoImghost = config["minio_img_host"]
  381. MinIoUploadDir = config["minio_upload_dir"]
  382. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  383. MinIoAccessKeyId = config["minio_access_key_id"]
  384. MinIoAccessKeySecret = config["minio_access_key_secret"]
  385. MinIoUseSSL = config["minio_use_ssl"]
  386. MinIoPort = config["minio_port"]
  387. MinIoRegion = config["minio_region"]
  388. }
  389. {
  390. S3Endpoint = config["s3_endpoint"]
  391. S3BackEndpoint = config["s3_back_endpoint"]
  392. S3BucketName = config["s3_bucket_name"]
  393. S3Host = config["s3_host"]
  394. S3AccessKeyId = config["s3_access_key_id"]
  395. S3AccessKeySecret = config["s3_access_key_secret"]
  396. S3UploadDir = config["s3_upload_dir"]
  397. S3Region = config["s3_region"]
  398. S3ForceStyle = config["s3_force_style"]
  399. S3EndpointPort = config["s3_endpoint_port"]
  400. S3Protocol = config["s3_protocol"]
  401. S3DisableSSL = config["s3_disable_ssl"]
  402. S3OpenAcl = config["s3_open_acl"]
  403. }
  404. PythonUrlReport2Img = config["python_url_report2img"]
  405. EtaAiUrl = config["eta_ai_url"]
  406. EtaAppid = config["eta_appid"]
  407. EtaSecret = config["eta_secret"]
  408. ChromePath = config["chrome_path"]
  409. initEs()
  410. ErrMsgConfigFile = config["err_msg_config_file"]
  411. if ErrMsgConfigFile != "" {
  412. viper.SetConfigFile(ErrMsgConfigFile)
  413. err = viper.ReadInConfig()
  414. if err != nil {
  415. if _, ok := err.(viper.ConfigFileNotFoundError); ok {
  416. fmt.Println(errors.New("config file not found"))
  417. panic(any("config file not found"))
  418. } else {
  419. fmt.Println(errors.New("config file was found but another error was produced err:" + err.Error()))
  420. panic(any("config file was found but another error was produced err:" + err.Error()))
  421. }
  422. return
  423. }
  424. ViperConfig = viper.GetViper()
  425. }
  426. }