config.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. )
  48. // TemplateIdByProduct 微信配置信息
  49. var (
  50. TemplateIdByProduct string //产品运行报告通知-模板ID
  51. WxYbAppId string // 研报小程序appid
  52. WxYbAppSecret string // 研报小程序秘钥
  53. )
  54. // ES配置
  55. var (
  56. ES_URL string // ES服务器地址
  57. ES_USERNAME string // ES账号
  58. ES_PASSWORD string // ES密码
  59. )
  60. // ES索引配置
  61. var (
  62. DATA_INDEX_NAME string //数据指标库索引
  63. CHART_INDEX_NAME string //研究图库索引
  64. EsReportIndexName string //研报ES索引
  65. EsEnglishReportIndexName string //英文研报ES索引
  66. MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
  67. )
  68. // 科大讯飞--语音合成
  69. var (
  70. XfHostUrl string
  71. )
  72. // 阿里云配置
  73. var (
  74. Bucketname string
  75. Endpoint string
  76. Imghost string
  77. UploadDir string
  78. Upload_Audio_Dir string
  79. AccessKeyId string
  80. AccessKeySecret string
  81. )
  82. // 阿里云oss前端上传用
  83. var (
  84. AliStsScheme string
  85. RegionId string
  86. RoleArn string
  87. RoleSessionName string
  88. RAMAccessKeyId string
  89. RAMAccessKeySecret string
  90. STSTokenCacheKey string
  91. )
  92. // 阿里云邮箱配置
  93. var (
  94. AliyunEmailAccountName string
  95. AliyunEmailAccessKeyId string
  96. AliyunEmailAccessKeySecret string
  97. )
  98. // 腾讯云邮箱配置
  99. var (
  100. TencentSDKSecretId string // 腾讯云主账号SecretId
  101. TencentSDKSecretKey string // 腾讯云主账号SecretKey
  102. TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
  103. TencentEmailTemplateID uint64 // 云邮件模板ID
  104. )
  105. // 日志配置
  106. var (
  107. LogPath string //调用过程中的日志存放地址
  108. LogFile string
  109. LogDataPath string //调用过程中图表相关的日志存放地址
  110. LogDataFile string
  111. BinLogPath string //数据库相关的日志存放地址
  112. BinLogFile string
  113. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  114. ApiLogFile string
  115. LogMaxDays int //日志最大保留天数
  116. )
  117. // BusinessCode 商家编码
  118. var BusinessCode string
  119. func init() {
  120. tmpRunMode, err := web.AppConfig.String("run_mode")
  121. if err != nil {
  122. panic("配置文件读取run_mode错误 " + err.Error())
  123. }
  124. RunMode = tmpRunMode
  125. fmt.Println("RunMode:", RunMode)
  126. if RunMode == "" {
  127. localIp, err := GetLocalIP()
  128. fmt.Println("localIp:", localIp)
  129. if localIp == "10.0.0.123" {
  130. RunMode = "debug"
  131. } else {
  132. RunMode = "release"
  133. }
  134. fmt.Println("RunMode:", RunMode)
  135. configPath := `/home/code/config/eta_mobile/conf/app.conf`
  136. fmt.Println("configPath:", configPath)
  137. err = web.LoadAppConfig("ini", configPath)
  138. if err != nil {
  139. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  140. }
  141. }
  142. config, err := web.AppConfig.GetSection(RunMode)
  143. if err != nil {
  144. panic("配置文件读取错误 " + err.Error())
  145. }
  146. beeLogger.Log.Info(RunMode + " 模式")
  147. MYSQL_URL = config["mysql_url"]
  148. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  149. MYSQL_URL_EDB = config["mysql_url_edb"]
  150. MYSQL_URL_DATA = config["mysql_url_data"]
  151. MYSQL_URL_GL = config["mysql_url_gl"]
  152. MYSQL_LOG_URL = config["mysql_url_log"]
  153. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  154. REDIS_CACHE = config["beego_cache"]
  155. if len(REDIS_CACHE) <= 0 {
  156. panic("redis链接参数没有配置")
  157. }
  158. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  159. if Re != nil {
  160. fmt.Println(Re)
  161. panic(Re)
  162. }
  163. // 项目中文名称
  164. appNameCn, err := web.AppConfig.String("app_name_cn")
  165. if err != nil {
  166. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  167. }
  168. APPNAME = appNameCn
  169. // 初始化内部服务配置
  170. // 接口返回加密KEY
  171. DesKey = config["des_key"]
  172. // 邮件提醒人员
  173. EmailSendToUsers = config["email_send_to_users"]
  174. // 静态文件目录
  175. STATIC_DIR = config["static_dir"]
  176. // 系统内部服务地址
  177. {
  178. // 公共指标库相关
  179. EDB_LIB_URL = config["edb_lib_url"]
  180. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  181. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  182. // 图表项目域名
  183. PublicChartHost = config["public_chart_host"]
  184. // 发送微信模板消息地址
  185. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  186. // 发送微信模板消息地址
  187. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  188. // 语音分贝处理的地址
  189. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  190. // 英文研报分享的地址
  191. EnglishShareUrl = config["english_share_url"]
  192. // 报警服务地址
  193. AlarmMsgUrl = config["alarm_msg_url"]
  194. }
  195. //日志配置
  196. {
  197. LogPath = config["log_path"]
  198. LogFile = config["log_file"]
  199. LogDataPath = config["log_data_path"]
  200. LogDataFile = config["log_data_file"]
  201. BinLogPath = config["binlog_path"]
  202. BinLogFile = config["binlog_file"]
  203. ApiLogPath = config["apilog_path"]
  204. ApiLogFile = config["apilog_file"]
  205. logMaxDaysStr := config["log_max_day"]
  206. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  207. }
  208. // ES配置
  209. {
  210. ES_URL = config["es_url"]
  211. ES_USERNAME = config["es_username"]
  212. ES_PASSWORD = config["es_password"]
  213. }
  214. // ES 索引
  215. {
  216. DATA_INDEX_NAME = config["data_index_name"]
  217. CHART_INDEX_NAME = config["chart_index_name"]
  218. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  219. EsReportIndexName = config["es_report_index_name"]
  220. EsEnglishReportIndexName = config["es_english_report_index_name"]
  221. }
  222. // 微信相关
  223. {
  224. //模板消息
  225. TemplateIdByProduct = config["template_id_by_product"]
  226. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  227. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  228. }
  229. // OSS相关
  230. {
  231. Endpoint = config["endpoint"]
  232. Bucketname = config["bucket_name"]
  233. Imghost = config["img_host"]
  234. UploadDir = config["upload_dir"]
  235. Upload_Audio_Dir = config["upload_audio_dir"]
  236. AccessKeyId = config["access_key_id"]
  237. AccessKeySecret = config["access_key_secret"]
  238. }
  239. // OSS相关(前端使用)
  240. {
  241. AliStsScheme = config["ali_sts_scheme"]
  242. RegionId = config["region_id"]
  243. RoleArn = config["role_arn"]
  244. RoleSessionName = config["role_session_name"]
  245. RAMAccessKeyId = config["ram_access_key_id"]
  246. RAMAccessKeySecret = config["ram_access_key_secret"]
  247. STSTokenCacheKey = config["sts_token_cache_key"]
  248. }
  249. // 阿里云邮箱配置
  250. {
  251. AliyunEmailAccountName = config["aliyun_email_account_name"]
  252. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  253. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  254. }
  255. // 腾讯云邮箱配置
  256. {
  257. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  258. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  259. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  260. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  261. if tencentEmailTemplateIDtr != `` {
  262. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  263. if err != nil {
  264. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  265. }
  266. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  267. }
  268. }
  269. // 科大讯飞
  270. {
  271. XfHostUrl = config["xf_host_url"]
  272. }
  273. // 商家编码
  274. BusinessCode = config["business_code"]
  275. // 初始化ES
  276. initEs()
  277. }