config.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. )
  137. func init() {
  138. tmpRunMode, err := web.AppConfig.String("run_mode")
  139. if err != nil {
  140. panic("配置文件读取run_mode错误 " + err.Error())
  141. }
  142. RunMode = tmpRunMode
  143. fmt.Println("RunMode:", RunMode)
  144. if RunMode == "" {
  145. localIp, err := GetLocalIP()
  146. fmt.Println("localIp:", localIp)
  147. if localIp == "10.0.0.123" {
  148. RunMode = "debug"
  149. } else {
  150. RunMode = "release"
  151. }
  152. fmt.Println("RunMode:", RunMode)
  153. configPath := `/home/code/config/eta_mobile/conf/app.conf`
  154. fmt.Println("configPath:", configPath)
  155. err = web.LoadAppConfig("ini", configPath)
  156. if err != nil {
  157. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  158. }
  159. }
  160. config, err := web.AppConfig.GetSection(RunMode)
  161. if err != nil {
  162. panic("配置文件读取错误 " + err.Error())
  163. }
  164. beeLogger.Log.Info(RunMode + " 模式")
  165. MYSQL_URL = config["mysql_url"]
  166. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  167. MYSQL_URL_EDB = config["mysql_url_edb"]
  168. MYSQL_URL_DATA = config["mysql_url_data"]
  169. MYSQL_URL_GL = config["mysql_url_gl"]
  170. MYSQL_LOG_URL = config["mysql_url_log"]
  171. MYSQL_URL_COMEIN_DATA = config["mysql_url_comein_data"]
  172. MYSQL_URL_ETA = config["mysql_url_eta"]
  173. REDIS_CACHE = config["beego_cache"]
  174. if len(REDIS_CACHE) <= 0 {
  175. panic("redis链接参数没有配置")
  176. }
  177. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  178. if Re != nil {
  179. fmt.Println(Re)
  180. panic(Re)
  181. }
  182. // 系统类型
  183. systemType, err := web.AppConfig.String("system_type")
  184. if err != nil {
  185. panic(any("配置文件读取system_type错误 " + err.Error()))
  186. }
  187. SystemType = systemType
  188. // 项目中文名称
  189. appNameCn, err := web.AppConfig.String("app_name_cn")
  190. if err != nil {
  191. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  192. }
  193. APPNAME = appNameCn
  194. // 初始化内部服务配置
  195. // 接口返回加密KEY
  196. DesKey = config["des_key"]
  197. // 服务基本配置
  198. {
  199. // 邮件提醒人员
  200. EmailSendToUsers = config["email_send_to_users"]
  201. // 静态文件目录
  202. STATIC_DIR = config["static_dir"]
  203. }
  204. // 系统内部服务地址
  205. {
  206. // 公共指标库相关
  207. EDB_LIB_URL = config["edb_lib_url"]
  208. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  209. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  210. // 图表项目域名
  211. PublicChartHost = config["public_chart_host"]
  212. // 发送微信模板消息地址
  213. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  214. // 发送微信模板消息地址
  215. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  216. // 语音分贝处理的地址
  217. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  218. // 英文研报分享的地址
  219. EnglishShareUrl = config["english_share_url"]
  220. // 报警服务地址
  221. AlarmMsgUrl = config["alarm_msg_url"]
  222. // ppt 转图片服务地址
  223. Ppt2ImageUrl = config["ppt2_image_url"]
  224. }
  225. //日志配置
  226. {
  227. LogPath = config["log_path"]
  228. LogFile = config["log_file"]
  229. LogDataPath = config["log_data_path"]
  230. LogDataFile = config["log_data_file"]
  231. BinLogPath = config["binlog_path"]
  232. BinLogFile = config["binlog_file"]
  233. ApiLogPath = config["apilog_path"]
  234. ApiLogFile = config["apilog_file"]
  235. }
  236. // ES配置
  237. {
  238. ES_URL = config["es_url"]
  239. ES_USERNAME = config["es_username"]
  240. ES_PASSWORD = config["es_password"]
  241. }
  242. // ES 索引
  243. {
  244. DATA_INDEX_NAME = config["data_index_name"]
  245. CHART_INDEX_NAME = config["chart_index_name"]
  246. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  247. EsReportIndexName = config["es_report_index_name"]
  248. EsEnglishReportIndexName = config["es_english_report_index_name"]
  249. }
  250. // 微信相关
  251. {
  252. //模板消息
  253. TemplateIdByProduct = config["template_id_by_product"]
  254. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  255. WxYbId = config["wx_yb_id"] // 研报小程序微信原始ID
  256. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  257. wxYbPlatformStr := config["wx_yb_platform"]
  258. if wxYbPlatformStr != `` {
  259. WxYbPlatform, err = strconv.Atoi(wxYbPlatformStr) //弘则研报来源
  260. if err != nil {
  261. panic(any("配置文件读取wx_yb_platform错误 " + err.Error()))
  262. }
  263. }
  264. }
  265. // OSS相关
  266. {
  267. Endpoint = config["endpoint"]
  268. Bucketname = config["bucket_name"]
  269. Imghost = config["img_host"]
  270. UploadDir = config["upload_dir"]
  271. Upload_Audio_Dir = config["upload_audio_dir"]
  272. AccessKeyId = config["access_key_id"]
  273. AccessKeySecret = config["access_key_secret"]
  274. }
  275. // OSS相关(前端使用)
  276. {
  277. AliStsScheme = config["ali_sts_scheme"]
  278. RegionId = config["region_id"]
  279. RoleArn = config["role_arn"]
  280. RoleSessionName = config["role_session_name"]
  281. RAMAccessKeyId = config["ram_access_key_id"]
  282. RAMAccessKeySecret = config["ram_access_key_secret"]
  283. STSTokenCacheKey = config["sts_token_cache_key"]
  284. }
  285. // 阿里云邮箱配置
  286. {
  287. AliyunEmailAccountName = config["aliyun_email_account_name"]
  288. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  289. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  290. AliyunEmailReplyAddress = config["aliyun_email_reply_address"]
  291. AliyunEmailReplyAddressAlias = config["aliyun_email_reply_address_alias"]
  292. }
  293. // 腾讯云邮箱配置
  294. {
  295. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  296. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  297. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  298. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  299. if tencentEmailTemplateIDtr != `` {
  300. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  301. if err != nil {
  302. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  303. }
  304. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  305. }
  306. }
  307. // 科大讯飞
  308. {
  309. XfAPPID = config["xf_appid"]
  310. XfAPIKey = config["xf_api_key"]
  311. XfAPISecret = config["xf_api_secret"]
  312. XfHostUrl = config["xf_host_url"]
  313. XfOrigin = config["xf_origin"]
  314. XfVcn = config["xf_vcn"]
  315. }
  316. LibreOfficePath = config["libre_office_path"]
  317. // 初始化ES
  318. initEs()
  319. }