config.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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_URL_COMEIN_DATA string // 路演记录数据库
  18. MYSQL_URL_ETA string
  19. REDIS_CACHE string //缓存地址
  20. Rc *cache.Cache //redis缓存
  21. Re error //redis错误
  22. )
  23. // SystemType 系统类型; hz:弘则;trial:试用平台;custom:客户
  24. var SystemType string
  25. // 基础配置
  26. var (
  27. STATIC_DIR string
  28. DesKey string // 接口返回加密KEY
  29. APPNAME string //项目中文名称
  30. EmailSendToUsers string // 邮件提醒人员
  31. // LibreOfficePath LibreOfficePath的地址
  32. LibreOfficePath string
  33. )
  34. // 公共api内部服务调用
  35. var (
  36. // EDB_LIB_URL 公共指标库
  37. EDB_LIB_URL string
  38. APP_EDB_LIB_NAME_EN string
  39. EDB_LIB_Md5_KEY string
  40. // PublicChartHost 公共图库的host
  41. PublicChartHost string
  42. // SendWxTemplateMsgUrl 模板消息推送
  43. SendWxTemplateMsgUrl string
  44. // SendTemplateMsgAuthorization 模板推送秘钥
  45. SendTemplateMsgAuthorization string
  46. // HandleVideoDecibelUrl 处理音频分贝的url
  47. HandleVideoDecibelUrl string
  48. // Ppt2ImageUrl ppt转图片服务的地址
  49. Ppt2ImageUrl string
  50. // EnglishShareUrl 英文研报群发邮件分享地址
  51. EnglishShareUrl string
  52. // AlarmMsgUrl 报警服务地址
  53. AlarmMsgUrl string
  54. )
  55. // TemplateIdByProduct 微信配置信息
  56. var (
  57. TemplateIdByProduct string //产品运行报告通知-模板ID
  58. WxYbAppId string // 研报小程序appid
  59. WxYbId string // 研报小程序微信原始ID
  60. WxYbAppSecret string // 研报小程序秘钥
  61. WxYbPlatform int //弘则研报来源
  62. )
  63. // ES配置
  64. var (
  65. ES_URL string // ES服务器地址
  66. ES_USERNAME string // ES账号
  67. ES_PASSWORD string // ES密码
  68. )
  69. // ES索引配置
  70. var (
  71. DATA_INDEX_NAME string //数据指标库索引
  72. CHART_INDEX_NAME string //研究图库索引
  73. EsReportIndexName string //研报ES索引
  74. EsEnglishReportIndexName string //英文研报ES索引
  75. MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
  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. XfSTATUS_FIRST_FRAME = 0 //第一帧标识
  100. XfSTATUS_CONTINUE_FRAME = 1 //中间帧标识
  101. XfSTATUS_LAST_FRAME = 2 //最后一帧标识
  102. XfHost = "tts-api.xfyun.cn"
  103. XfMaxFontSize = 8000
  104. XfAPPID string
  105. XfAPIKey string
  106. XfAPISecret string
  107. XfHostUrl string
  108. XfOrigin string
  109. XfVcn string //发言人
  110. )
  111. // 阿里云邮箱配置
  112. var (
  113. AliyunEmailAccountName string
  114. AliyunEmailAccessKeyId string
  115. AliyunEmailAccessKeySecret string
  116. AliyunEmailReplyAddress string
  117. AliyunEmailReplyAddressAlias string
  118. )
  119. // 腾讯云邮箱配置
  120. var (
  121. TencentSDKSecretId string // 腾讯云主账号SecretId
  122. TencentSDKSecretKey string // 腾讯云主账号SecretKey
  123. TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
  124. TencentEmailTemplateID uint64 // 云邮件模板ID
  125. )
  126. // 日志配置
  127. var (
  128. LogPath string //调用过程中的日志存放地址
  129. LogFile string
  130. LogDataPath string //调用过程中图表相关的日志存放地址
  131. LogDataFile string
  132. BinLogPath string //数据库相关的日志存放地址
  133. BinLogFile string
  134. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  135. ApiLogFile string
  136. LogMaxDays int //日志最大保留天数
  137. )
  138. func init() {
  139. tmpRunMode, err := web.AppConfig.String("run_mode")
  140. if err != nil {
  141. panic("配置文件读取run_mode错误 " + err.Error())
  142. }
  143. RunMode = tmpRunMode
  144. fmt.Println("RunMode:", RunMode)
  145. if RunMode == "" {
  146. localIp, err := GetLocalIP()
  147. fmt.Println("localIp:", localIp)
  148. if localIp == "10.0.0.123" {
  149. RunMode = "debug"
  150. } else {
  151. RunMode = "release"
  152. }
  153. fmt.Println("RunMode:", RunMode)
  154. configPath := `/home/code/config/eta_mobile/conf/app.conf`
  155. fmt.Println("configPath:", configPath)
  156. err = web.LoadAppConfig("ini", configPath)
  157. if err != nil {
  158. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  159. }
  160. }
  161. config, err := web.AppConfig.GetSection(RunMode)
  162. if err != nil {
  163. panic("配置文件读取错误 " + err.Error())
  164. }
  165. beeLogger.Log.Info(RunMode + " 模式")
  166. MYSQL_URL = config["mysql_url"]
  167. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  168. MYSQL_URL_EDB = config["mysql_url_edb"]
  169. MYSQL_URL_DATA = config["mysql_url_data"]
  170. MYSQL_URL_GL = config["mysql_url_gl"]
  171. MYSQL_LOG_URL = config["mysql_url_log"]
  172. MYSQL_URL_COMEIN_DATA = config["mysql_url_comein_data"]
  173. MYSQL_URL_ETA = config["mysql_url_eta"]
  174. REDIS_CACHE = config["beego_cache"]
  175. if len(REDIS_CACHE) <= 0 {
  176. panic("redis链接参数没有配置")
  177. }
  178. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  179. if Re != nil {
  180. fmt.Println(Re)
  181. panic(Re)
  182. }
  183. // 系统类型
  184. systemType, err := web.AppConfig.String("system_type")
  185. if err != nil {
  186. panic(any("配置文件读取system_type错误 " + err.Error()))
  187. }
  188. SystemType = systemType
  189. // 项目中文名称
  190. appNameCn, err := web.AppConfig.String("app_name_cn")
  191. if err != nil {
  192. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  193. }
  194. APPNAME = appNameCn
  195. // 初始化内部服务配置
  196. // 接口返回加密KEY
  197. DesKey = config["des_key"]
  198. // 服务基本配置
  199. {
  200. // 邮件提醒人员
  201. EmailSendToUsers = config["email_send_to_users"]
  202. // 静态文件目录
  203. STATIC_DIR = config["static_dir"]
  204. }
  205. // 系统内部服务地址
  206. {
  207. // 公共指标库相关
  208. EDB_LIB_URL = config["edb_lib_url"]
  209. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  210. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  211. // 图表项目域名
  212. PublicChartHost = config["public_chart_host"]
  213. // 发送微信模板消息地址
  214. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  215. // 发送微信模板消息地址
  216. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  217. // 语音分贝处理的地址
  218. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  219. // 英文研报分享的地址
  220. EnglishShareUrl = config["english_share_url"]
  221. // 报警服务地址
  222. AlarmMsgUrl = config["alarm_msg_url"]
  223. // ppt 转图片服务地址
  224. Ppt2ImageUrl = config["ppt2_image_url"]
  225. }
  226. //日志配置
  227. {
  228. LogPath = config["log_path"]
  229. LogFile = config["log_file"]
  230. LogDataPath = config["log_data_path"]
  231. LogDataFile = config["log_data_file"]
  232. BinLogPath = config["binlog_path"]
  233. BinLogFile = config["binlog_file"]
  234. ApiLogPath = config["apilog_path"]
  235. ApiLogFile = config["apilog_file"]
  236. logMaxDaysStr := config["log_max_day"]
  237. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  238. }
  239. // ES配置
  240. {
  241. ES_URL = config["es_url"]
  242. ES_USERNAME = config["es_username"]
  243. ES_PASSWORD = config["es_password"]
  244. }
  245. // ES 索引
  246. {
  247. DATA_INDEX_NAME = config["data_index_name"]
  248. CHART_INDEX_NAME = config["chart_index_name"]
  249. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  250. EsReportIndexName = config["es_report_index_name"]
  251. EsEnglishReportIndexName = config["es_english_report_index_name"]
  252. }
  253. // 微信相关
  254. {
  255. //模板消息
  256. TemplateIdByProduct = config["template_id_by_product"]
  257. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  258. WxYbId = config["wx_yb_id"] // 研报小程序微信原始ID
  259. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  260. wxYbPlatformStr := config["wx_yb_platform"]
  261. if wxYbPlatformStr != `` {
  262. WxYbPlatform, err = strconv.Atoi(wxYbPlatformStr) //弘则研报来源
  263. if err != nil {
  264. panic(any("配置文件读取wx_yb_platform错误 " + err.Error()))
  265. }
  266. }
  267. }
  268. // OSS相关
  269. {
  270. Endpoint = config["endpoint"]
  271. Bucketname = config["bucket_name"]
  272. Imghost = config["img_host"]
  273. UploadDir = config["upload_dir"]
  274. Upload_Audio_Dir = config["upload_audio_dir"]
  275. AccessKeyId = config["access_key_id"]
  276. AccessKeySecret = config["access_key_secret"]
  277. }
  278. // OSS相关(前端使用)
  279. {
  280. AliStsScheme = config["ali_sts_scheme"]
  281. RegionId = config["region_id"]
  282. RoleArn = config["role_arn"]
  283. RoleSessionName = config["role_session_name"]
  284. RAMAccessKeyId = config["ram_access_key_id"]
  285. RAMAccessKeySecret = config["ram_access_key_secret"]
  286. STSTokenCacheKey = config["sts_token_cache_key"]
  287. }
  288. // 阿里云邮箱配置
  289. {
  290. AliyunEmailAccountName = config["aliyun_email_account_name"]
  291. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  292. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  293. AliyunEmailReplyAddress = config["aliyun_email_reply_address"]
  294. AliyunEmailReplyAddressAlias = config["aliyun_email_reply_address_alias"]
  295. }
  296. // 腾讯云邮箱配置
  297. {
  298. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  299. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  300. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  301. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  302. if tencentEmailTemplateIDtr != `` {
  303. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  304. if err != nil {
  305. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  306. }
  307. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  308. }
  309. }
  310. // 科大讯飞
  311. {
  312. XfAPPID = config["xf_appid"]
  313. XfAPIKey = config["xf_api_key"]
  314. XfAPISecret = config["xf_api_secret"]
  315. XfHostUrl = config["xf_host_url"]
  316. XfOrigin = config["xf_origin"]
  317. XfVcn = config["xf_vcn"]
  318. }
  319. LibreOfficePath = config["libre_office_path"]
  320. // 初始化ES
  321. initEs()
  322. }