config.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_RDDP string //数据库连接
  13. MYSQL_URL_EDB string
  14. MYSQL_URL_DATA string
  15. MYSQL_URL_GL string
  16. MYSQL_LOG_URL string
  17. MYSQL_WEEKLY_URL string //用户主库
  18. REDIS_CACHE string //缓存地址
  19. Rc *cache.Cache //redis缓存
  20. Re error //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. // BusinessCode 商家编码
  123. var BusinessCode string
  124. // MinIo配置
  125. var (
  126. MinIoBucketname string
  127. MinIoEndpoint string
  128. MinIoBackEndpoint string
  129. MinIoImghost string
  130. MinIoUploadDir string
  131. MinIoUpload_Audio_Dir string
  132. MinIoAccessKeyId string
  133. MinIoAccessKeySecret string
  134. MinIoUseSSL string
  135. MinIoPort string
  136. MinIoRegion string
  137. )
  138. // 对象存储客户端
  139. var (
  140. ObjectStorageClient string // 目前有oss minio,默认oss
  141. )
  142. // S3配置
  143. var (
  144. S3Endpoint string
  145. S3BucketName string
  146. S3UploadDir string
  147. S3AccessKeyId string
  148. S3AccessKeySecret string
  149. S3Host string
  150. S3Region string
  151. S3ForceStyle string
  152. S3EndpointPort string
  153. S3Protocol string
  154. )
  155. func init() {
  156. tmpRunMode, err := web.AppConfig.String("run_mode")
  157. if err != nil {
  158. panic("配置文件读取run_mode错误 " + err.Error())
  159. }
  160. RunMode = tmpRunMode
  161. fmt.Println("RunMode:", RunMode)
  162. if RunMode == "" {
  163. localIp, err := GetLocalIP()
  164. fmt.Println("localIp:", localIp)
  165. if localIp == "10.0.0.123" {
  166. RunMode = "debug"
  167. } else {
  168. RunMode = "release"
  169. }
  170. fmt.Println("RunMode:", RunMode)
  171. configPath := `/home/code/config/eta_mobile/conf/app.conf`
  172. fmt.Println("configPath:", configPath)
  173. err = web.LoadAppConfig("ini", configPath)
  174. if err != nil {
  175. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  176. }
  177. }
  178. config, err := web.AppConfig.GetSection(RunMode)
  179. if err != nil {
  180. panic("配置文件读取错误 " + err.Error())
  181. }
  182. beeLogger.Log.Info(RunMode + " 模式")
  183. MYSQL_URL = config["mysql_url"]
  184. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  185. MYSQL_URL_EDB = config["mysql_url_edb"]
  186. MYSQL_URL_DATA = config["mysql_url_data"]
  187. MYSQL_URL_GL = config["mysql_url_gl"]
  188. MYSQL_LOG_URL = config["mysql_url_log"]
  189. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  190. REDIS_CACHE = config["beego_cache"]
  191. if len(REDIS_CACHE) <= 0 {
  192. panic("redis链接参数没有配置")
  193. }
  194. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  195. if Re != nil {
  196. fmt.Println(Re)
  197. panic(Re)
  198. }
  199. // 项目中文名称
  200. appNameCn, err := web.AppConfig.String("app_name_cn")
  201. if err != nil {
  202. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  203. }
  204. APPNAME = appNameCn
  205. // 初始化内部服务配置
  206. // 接口返回加密KEY
  207. DesKey = config["des_key"]
  208. // 邮件提醒人员
  209. EmailSendToUsers = config["email_send_to_users"]
  210. // 静态文件目录
  211. STATIC_DIR = config["static_dir"]
  212. // 系统内部服务地址
  213. {
  214. // 公共指标库相关
  215. EDB_LIB_URL = config["edb_lib_url"]
  216. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  217. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  218. // 图表项目域名
  219. PublicChartHost = config["public_chart_host"]
  220. // 发送微信模板消息地址
  221. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  222. // 发送微信模板消息地址
  223. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  224. // 语音分贝处理的地址
  225. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  226. // 英文研报分享的地址
  227. EnglishShareUrl = config["english_share_url"]
  228. // 报警服务地址
  229. AlarmMsgUrl = config["alarm_msg_url"]
  230. EtaBridgeUrl = config["eta_bridge_url"] // 桥接服务地址
  231. EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
  232. EtaBridgeMd5Key = config["eta_bridge_md5_key"] // 桥接服务Md5密钥-鉴权用
  233. EtaBridgeDesKey = config["eta_bridge_des_key"] // 桥接服务Des密钥-解密数据用
  234. }
  235. //日志配置
  236. {
  237. LogPath = config["log_path"]
  238. LogFile = config["log_file"]
  239. LogDataPath = config["log_data_path"]
  240. LogDataFile = config["log_data_file"]
  241. BinLogPath = config["binlog_path"]
  242. BinLogFile = config["binlog_file"]
  243. ApiLogPath = config["apilog_path"]
  244. ApiLogFile = config["apilog_file"]
  245. logMaxDaysStr := config["log_max_day"]
  246. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  247. }
  248. // ES配置
  249. {
  250. ES_URL = config["es_url"]
  251. ES_USERNAME = config["es_username"]
  252. ES_PASSWORD = config["es_password"]
  253. }
  254. // ES 索引
  255. {
  256. DATA_INDEX_NAME = config["data_index_name"]
  257. CHART_INDEX_NAME = config["chart_index_name"]
  258. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  259. EsReportIndexName = config["es_report_index_name"]
  260. EsEnglishReportIndexName = config["es_english_report_index_name"]
  261. SmartReportIndexName = config["es_smart_report_index_name"]
  262. }
  263. // 微信相关
  264. {
  265. //模板消息
  266. TemplateIdByProduct = config["template_id_by_product"]
  267. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  268. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  269. }
  270. // 对象存储客户端
  271. ObjectStorageClient = config["object_storage_client"]
  272. // OSS相关
  273. {
  274. Endpoint = config["endpoint"]
  275. Bucketname = config["bucket_name"]
  276. Imghost = config["img_host"]
  277. UploadDir = config["upload_dir"]
  278. Upload_Audio_Dir = config["upload_audio_dir"]
  279. AccessKeyId = config["access_key_id"]
  280. AccessKeySecret = config["access_key_secret"]
  281. }
  282. // OSS相关(前端使用)
  283. {
  284. AliStsScheme = config["ali_sts_scheme"]
  285. RegionId = config["region_id"]
  286. RoleArn = config["role_arn"]
  287. RoleSessionName = config["role_session_name"]
  288. RAMAccessKeyId = config["ram_access_key_id"]
  289. RAMAccessKeySecret = config["ram_access_key_secret"]
  290. STSTokenCacheKey = config["sts_token_cache_key"]
  291. }
  292. // 阿里云邮箱配置
  293. {
  294. AliyunEmailAccountName = config["aliyun_email_account_name"]
  295. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  296. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  297. }
  298. // 腾讯云邮箱配置
  299. {
  300. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  301. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  302. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  303. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  304. if tencentEmailTemplateIDtr != `` {
  305. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  306. if err != nil {
  307. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  308. }
  309. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  310. }
  311. }
  312. // 科大讯飞
  313. {
  314. XfHostUrl = config["xf_host_url"]
  315. }
  316. // MinIo相关
  317. {
  318. MinIoEndpoint = config["minio_endpoint"]
  319. MinIoBackEndpoint = config["minio_back_endpoint"]
  320. MinIoBucketname = config["minio_bucket_name"]
  321. MinIoImghost = config["minio_img_host"]
  322. MinIoUploadDir = config["minio_upload_dir"]
  323. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  324. MinIoAccessKeyId = config["minio_access_key_id"]
  325. MinIoAccessKeySecret = config["minio_access_key_secret"]
  326. MinIoUseSSL = config["minio_use_ssl"]
  327. MinIoPort = config["minio_port"]
  328. MinIoRegion = config["minio_region"]
  329. }
  330. // S3-OSS相关
  331. {
  332. S3Endpoint = config["s3_endpoint"]
  333. S3BucketName = config["s3_bucket_name"]
  334. S3Host = config["s3_host"]
  335. S3AccessKeyId = config["s3_access_key_id"]
  336. S3AccessKeySecret = config["s3_access_key_secret"]
  337. S3UploadDir = config["s3_upload_dir"]
  338. S3Region = config["s3_region"]
  339. S3ForceStyle = config["s3_force_style"]
  340. S3EndpointPort = config["s3_endpoint_port"]
  341. S3Protocol = config["s3_protocol"]
  342. }
  343. // 商家编码
  344. BusinessCode = config["business_code"]
  345. // 初始化ES
  346. initEs()
  347. }