config.go 11 KB

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