config.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "strconv"
  7. )
  8. var (
  9. RunMode string //运行模式
  10. MYSQL_URL string //数据库连接
  11. MYSQL_URL_RDDP string //数据库连接
  12. MYSQL_URL_EDB string
  13. MYSQL_URL_DATA string
  14. MYSQL_URL_GL string
  15. MYSQL_LOG_URL string
  16. MYSQL_WEEKLY_URL string //用户主库
  17. REDIS_CACHE string //缓存地址
  18. //Rc *cache.Cache //redis缓存
  19. Re error //redis错误
  20. Rc RedisClient //redis缓存
  21. )
  22. // 基础配置
  23. var (
  24. STATIC_DIR string
  25. DesKey string // 接口返回加密KEY
  26. APPNAME string //项目中文名称
  27. EmailSendToUsers string // 邮件提醒人员
  28. ResourceProxyUrl string // 代理资源地址
  29. RESOURCE_DIR string
  30. )
  31. // 公共api内部服务调用
  32. var (
  33. // EDB_LIB_URL 公共指标库
  34. EDB_LIB_URL string
  35. APP_EDB_LIB_NAME_EN string
  36. EDB_LIB_Md5_KEY string
  37. // PublicChartHost 公共图库的host
  38. PublicChartHost string
  39. // SendWxTemplateMsgUrl 模板消息推送
  40. SendWxTemplateMsgUrl string
  41. // SendTemplateMsgAuthorization 模板推送秘钥
  42. SendTemplateMsgAuthorization string
  43. // HandleVideoDecibelUrl 处理音频分贝的url
  44. HandleVideoDecibelUrl string
  45. // EnglishShareUrl 英文研报群发邮件分享地址
  46. EnglishShareUrl string
  47. // EnPolicyReportUrl 英文策略报告
  48. EnPolicyReportUrl string
  49. // GoogleTranslateUrl 谷歌翻译服务
  50. GoogleTranslateUrl string
  51. // AlarmMsgUrl 报警服务地址
  52. AlarmMsgUrl string
  53. EtaBridgeUrl string // 桥接服务地址
  54. EtaBridgeAppNameEn string // 桥接服务英文名称-鉴权用
  55. EtaBridgeMd5Key string // 桥接服务Md5密钥-鉴权用
  56. EtaBridgeDesKey string // 桥接服务Des密钥-解密数据用
  57. EtaBridgeLoginUrl string // 第三方登录鉴权接口地址
  58. EtaBridgeLogoutUrl string // 第三方登出接口地址
  59. )
  60. // TemplateIdByProduct 微信配置信息
  61. var (
  62. TemplateIdByProduct string //产品运行报告通知-模板ID
  63. WxYbAppId string // 研报小程序appid
  64. WxYbAppSecret string // 研报小程序秘钥
  65. )
  66. // ES配置
  67. var (
  68. ES_URL string // ES服务器地址
  69. ES_USERNAME string // ES账号
  70. ES_PASSWORD string // ES密码
  71. )
  72. // ES索引配置
  73. var (
  74. DATA_INDEX_NAME string //数据指标库索引
  75. CHART_INDEX_NAME string //研究图库索引
  76. EsReportIndexName string //研报ES索引
  77. EsEnglishReportIndexName string //英文研报ES索引
  78. MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
  79. SmartReportIndexName string //智能研报ES索引
  80. )
  81. // 科大讯飞--语音合成
  82. var (
  83. XfHostUrl string
  84. )
  85. // 阿里云配置
  86. var (
  87. Bucketname string
  88. Endpoint string
  89. Imghost string
  90. UploadDir string
  91. Upload_Audio_Dir string
  92. AccessKeyId string
  93. AccessKeySecret string
  94. )
  95. // 阿里云oss前端上传用
  96. var (
  97. AliStsScheme string
  98. RegionId string
  99. RoleArn string
  100. RoleSessionName string
  101. RAMAccessKeyId string
  102. RAMAccessKeySecret string
  103. STSTokenCacheKey string
  104. )
  105. // 阿里云邮箱配置
  106. var (
  107. AliyunEmailAccountName string
  108. AliyunEmailAccessKeyId string
  109. AliyunEmailAccessKeySecret string
  110. )
  111. // 腾讯云邮箱配置
  112. var (
  113. TencentSDKSecretId string // 腾讯云主账号SecretId
  114. TencentSDKSecretKey string // 腾讯云主账号SecretKey
  115. TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
  116. TencentEmailTemplateID uint64 // 云邮件模板ID
  117. )
  118. // 日志配置
  119. var (
  120. LogPath string //调用过程中的日志存放地址
  121. LogFile string
  122. LogDataPath string //调用过程中图表相关的日志存放地址
  123. LogDataFile string
  124. BinLogPath string //数据库相关的日志存放地址
  125. BinLogFile string
  126. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  127. ApiLogFile string
  128. LogMaxDays int //日志最大保留天数
  129. )
  130. // CrmEtaServerUrl CRM-ETA服务地址
  131. var (
  132. CrmEtaServerUrl string
  133. CrmEtaServerDes3Key string
  134. )
  135. // BusinessCode 商家编码
  136. var BusinessCode string
  137. // MinIo配置
  138. var (
  139. MinIoBucketname string
  140. MinIoEndpoint string
  141. MinIoBackEndpoint string
  142. MinIoImghost string
  143. MinIoUploadDir string
  144. MinIoUpload_Audio_Dir string
  145. MinIoAccessKeyId string
  146. MinIoAccessKeySecret string
  147. MinIoUseSSL string
  148. MinIoPort string
  149. MinIoRegion string
  150. )
  151. // 对象存储客户端
  152. var (
  153. ObjectStorageClient string // 目前有oss minio,默认oss
  154. )
  155. // S3配置
  156. var (
  157. S3Endpoint string
  158. S3BucketName string
  159. S3UploadDir string
  160. S3AccessKeyId string
  161. S3AccessKeySecret string
  162. S3Host string
  163. S3Region string
  164. S3ForceStyle string
  165. S3EndpointPort string
  166. S3Protocol string
  167. )
  168. func init() {
  169. tmpRunMode, err := web.AppConfig.String("run_mode")
  170. if err != nil {
  171. panic("配置文件读取run_mode错误 " + err.Error())
  172. }
  173. RunMode = tmpRunMode
  174. fmt.Println("RunMode:", RunMode)
  175. if RunMode == "" {
  176. localIp, err := GetLocalIP()
  177. fmt.Println("localIp:", localIp)
  178. if localIp == "10.0.0.123" {
  179. RunMode = "debug"
  180. } else {
  181. RunMode = "release"
  182. }
  183. fmt.Println("RunMode:", RunMode)
  184. configPath := `/home/code/config/eta_mobile/conf/app.conf`
  185. fmt.Println("configPath:", configPath)
  186. err = web.LoadAppConfig("ini", configPath)
  187. if err != nil {
  188. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  189. }
  190. }
  191. config, err := web.AppConfig.GetSection(RunMode)
  192. if err != nil {
  193. panic("配置文件读取错误 " + err.Error())
  194. }
  195. beeLogger.Log.Info(RunMode + " 模式")
  196. MYSQL_URL = config["mysql_url"]
  197. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  198. MYSQL_URL_EDB = config["mysql_url_edb"]
  199. MYSQL_URL_DATA = config["mysql_url_data"]
  200. MYSQL_URL_GL = config["mysql_url_gl"]
  201. MYSQL_LOG_URL = config["mysql_url_log"]
  202. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  203. REDIS_CACHE = config["beego_cache"]
  204. if len(REDIS_CACHE) <= 0 {
  205. panic("redis链接参数没有配置")
  206. }
  207. //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  208. //if Re != nil {
  209. // fmt.Println(Re)
  210. // panic(Re)
  211. //}
  212. // 初始化缓存
  213. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  214. if err != nil {
  215. fmt.Println("redis链接异常:", err)
  216. panic(any(Re))
  217. }
  218. Rc = redisClient
  219. // 项目中文名称
  220. appNameCn, err := web.AppConfig.String("app_name_cn")
  221. if err != nil {
  222. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  223. }
  224. APPNAME = appNameCn
  225. // 初始化内部服务配置
  226. // 接口返回加密KEY
  227. DesKey = config["des_key"]
  228. // 邮件提醒人员
  229. EmailSendToUsers = config["email_send_to_users"]
  230. // 静态文件目录
  231. STATIC_DIR = config["static_dir"]
  232. // 代理资源地址
  233. ResourceProxyUrl = config["resource_proxy_url"]
  234. RESOURCE_DIR = config["resource_dir"]
  235. if RESOURCE_DIR == "" {
  236. RESOURCE_DIR = "eta/"
  237. }
  238. // 系统内部服务地址
  239. {
  240. // 公共指标库相关
  241. EDB_LIB_URL = config["edb_lib_url"]
  242. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  243. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  244. // 图表项目域名
  245. PublicChartHost = config["public_chart_host"]
  246. // 发送微信模板消息地址
  247. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  248. // 发送微信模板消息地址
  249. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  250. // 语音分贝处理的地址
  251. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  252. // 英文研报分享的地址
  253. EnglishShareUrl = config["english_share_url"]
  254. // 策略报告地址
  255. EnPolicyReportUrl = config["en_policy_report_url"]
  256. // 谷歌翻译服务地址
  257. GoogleTranslateUrl = config["google_translate_url"]
  258. // 报警服务地址
  259. AlarmMsgUrl = config["alarm_msg_url"]
  260. EtaBridgeUrl = config["eta_bridge_url"] // 桥接服务地址
  261. EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
  262. EtaBridgeMd5Key = config["eta_bridge_md5_key"] // 桥接服务Md5密钥-鉴权用
  263. EtaBridgeDesKey = config["eta_bridge_des_key"] // 桥接服务Des密钥-解密数据用
  264. EtaBridgeLoginUrl = config["eta_bridge_login_url"] // eta桥接服务-登录接口地址
  265. EtaBridgeLogoutUrl = config["eta_bridge_logout_url"] // eta桥接服务-登出接口地址
  266. }
  267. //日志配置
  268. {
  269. LogPath = config["log_path"]
  270. LogFile = config["log_file"]
  271. LogDataPath = config["log_data_path"]
  272. LogDataFile = config["log_data_file"]
  273. BinLogPath = config["binlog_path"]
  274. BinLogFile = config["binlog_file"]
  275. ApiLogPath = config["apilog_path"]
  276. ApiLogFile = config["apilog_file"]
  277. logMaxDaysStr := config["log_max_day"]
  278. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  279. }
  280. {
  281. CrmEtaServerUrl = config["crm_eta_server_url"]
  282. CrmEtaServerDes3Key = config["crm_eta_server_des3_key"]
  283. }
  284. // ES配置
  285. {
  286. ES_URL = config["es_url"]
  287. ES_USERNAME = config["es_username"]
  288. ES_PASSWORD = config["es_password"]
  289. }
  290. // ES 索引
  291. {
  292. DATA_INDEX_NAME = config["data_index_name"]
  293. CHART_INDEX_NAME = config["chart_index_name"]
  294. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  295. EsReportIndexName = config["es_report_index_name"]
  296. EsEnglishReportIndexName = config["es_english_report_index_name"]
  297. SmartReportIndexName = config["es_smart_report_index_name"]
  298. }
  299. // 微信相关
  300. {
  301. //模板消息
  302. TemplateIdByProduct = config["template_id_by_product"]
  303. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  304. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  305. }
  306. // 对象存储客户端
  307. ObjectStorageClient = config["object_storage_client"]
  308. // OSS相关
  309. {
  310. Endpoint = config["endpoint"]
  311. Bucketname = config["bucket_name"]
  312. Imghost = config["img_host"]
  313. UploadDir = config["upload_dir"]
  314. Upload_Audio_Dir = config["upload_audio_dir"]
  315. AccessKeyId = config["access_key_id"]
  316. AccessKeySecret = config["access_key_secret"]
  317. }
  318. // OSS相关(前端使用)
  319. {
  320. AliStsScheme = config["ali_sts_scheme"]
  321. RegionId = config["region_id"]
  322. RoleArn = config["role_arn"]
  323. RoleSessionName = config["role_session_name"]
  324. RAMAccessKeyId = config["ram_access_key_id"]
  325. RAMAccessKeySecret = config["ram_access_key_secret"]
  326. STSTokenCacheKey = config["sts_token_cache_key"]
  327. }
  328. // 阿里云邮箱配置
  329. {
  330. AliyunEmailAccountName = config["aliyun_email_account_name"]
  331. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  332. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  333. }
  334. // 腾讯云邮箱配置
  335. {
  336. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  337. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  338. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  339. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  340. if tencentEmailTemplateIDtr != `` {
  341. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  342. if err != nil {
  343. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  344. }
  345. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  346. }
  347. }
  348. // 科大讯飞
  349. {
  350. XfHostUrl = config["xf_host_url"]
  351. }
  352. // MinIo相关
  353. {
  354. MinIoEndpoint = config["minio_endpoint"]
  355. MinIoBackEndpoint = config["minio_back_endpoint"]
  356. MinIoBucketname = config["minio_bucket_name"]
  357. MinIoImghost = config["minio_img_host"]
  358. MinIoUploadDir = config["minio_upload_dir"]
  359. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  360. MinIoAccessKeyId = config["minio_access_key_id"]
  361. MinIoAccessKeySecret = config["minio_access_key_secret"]
  362. MinIoUseSSL = config["minio_use_ssl"]
  363. MinIoPort = config["minio_port"]
  364. MinIoRegion = config["minio_region"]
  365. }
  366. // S3-OSS相关
  367. {
  368. S3Endpoint = config["s3_endpoint"]
  369. S3BucketName = config["s3_bucket_name"]
  370. S3Host = config["s3_host"]
  371. S3AccessKeyId = config["s3_access_key_id"]
  372. S3AccessKeySecret = config["s3_access_key_secret"]
  373. S3UploadDir = config["s3_upload_dir"]
  374. S3Region = config["s3_region"]
  375. S3ForceStyle = config["s3_force_style"]
  376. S3EndpointPort = config["s3_endpoint_port"]
  377. S3Protocol = config["s3_protocol"]
  378. }
  379. // 商家编码
  380. BusinessCode = config["business_code"]
  381. // 初始化ES
  382. initEs()
  383. }