config.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package utils
  2. import (
  3. "fmt"
  4. beego "github.com/beego/beego/v2/adapter"
  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_URL_ETA string
  16. )
  17. var (
  18. LogPath string
  19. LogFile string
  20. BinLogPath string
  21. BinLogFile string
  22. LogMaxDays int //日志最大保留天数
  23. )
  24. var (
  25. APPNAME string //项目中文名称
  26. EmailSendToUsers string // 邮件提醒人员
  27. RefreshEdbInfoEmailSendToUsers string // 刷新完成通知邮件人员
  28. // AlarmMsgUrl 报警服务地址
  29. AlarmMsgUrl string
  30. )
  31. // 经济数据库
  32. var (
  33. EDB_LIB_URL string
  34. APP_EDB_LIB_NAME_EN string
  35. EDB_LIB_Md5_KEY string
  36. )
  37. // 公共数据服务接口参数
  38. var (
  39. APPID string
  40. SECRET string
  41. )
  42. var (
  43. WxAppId string
  44. WxAppSecret string
  45. TemplateId string
  46. RemindTemplateId string
  47. AppointmentRemindTemplateId string //活动预约通知模板id
  48. YbCommonTemplateId string //研报小程序消息模板ID
  49. SendWxTemplateEnable string //是否开启模版消息,1是发送,其他不发送
  50. WxYbAppId string //微信研报小程序
  51. //内部员工公众号(弘则部门)
  52. AdminWxAppId string
  53. AdminWxAppSecret string
  54. )
  55. // 模板消息推送
  56. var (
  57. SendWxTemplateMsgUrl string
  58. )
  59. // BusinessCode 商家编码
  60. var (
  61. BusinessCode string //商户号
  62. WindServerUrl string //wind api 接口服务器地址
  63. LtServerUrl string //路透 api 接口服务器地址
  64. PbServerUrl string //彭博 api 接口服务器地址
  65. )
  66. // ES配置
  67. var (
  68. ES_URL string // ES服务器地址
  69. ES_USERNAME string // ES账号
  70. ES_PASSWORD string // ES密码
  71. )
  72. var (
  73. EsReportIndexName string //研报ES索引
  74. EsEnglishReportIndexName string //英文研报ES索引
  75. )
  76. // 科大讯飞--语音合成
  77. var (
  78. XfHostUrl string
  79. )
  80. var (
  81. TemplateIdByProduct string //产品运行报告通知-模板ID
  82. )
  83. // 阿里云配置
  84. var (
  85. Bucketname string
  86. Endpoint string
  87. Imghost string
  88. UploadDir string
  89. Upload_Audio_Dir string
  90. AccessKeyId string
  91. AccessKeySecret string
  92. )
  93. var HzDataApi string
  94. func init() {
  95. tmpRunMode, err := web.AppConfig.String("run_mode")
  96. if err != nil {
  97. panic("配置文件读取run_mode错误 " + err.Error())
  98. }
  99. RunMode = tmpRunMode
  100. if RunMode == "" {
  101. localIp, err := GetLocalIP()
  102. fmt.Println("localIp:", localIp)
  103. if localIp == "10.0.0.123" {
  104. RunMode = "debug"
  105. } else {
  106. RunMode = "release"
  107. }
  108. //RunMode = "release"
  109. configPath := `/home/code/config/eta_task/conf/app.conf`
  110. err = web.LoadAppConfig("ini", configPath)
  111. if err != nil {
  112. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  113. }
  114. }
  115. config, err := web.AppConfig.GetSection(RunMode)
  116. if err != nil {
  117. panic("配置文件读取错误 " + err.Error())
  118. }
  119. beego.Info(RunMode + " 模式")
  120. MYSQL_URL = config["mysql_url"]
  121. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  122. MYSQL_URL_EDB = config["mysql_url_edb"]
  123. MYSQL_URL_DATA = config["mysql_url_data"]
  124. MYSQL_URL_GL = config["mysql_url_gl"]
  125. MYSQL_URL_ETA = config["mysql_url_eta"]
  126. // 项目中文名称
  127. appNameCn, err := web.AppConfig.String("app_name_cn")
  128. if err != nil {
  129. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  130. }
  131. APPNAME = appNameCn
  132. {
  133. LogPath = config["log_path"]
  134. LogFile = config["log_file"]
  135. BinLogPath = config["binlog_path"]
  136. BinLogFile = config["binlog_file"]
  137. logMaxDaysStr := config["log_max_day"]
  138. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  139. }
  140. // 邮件提醒人员
  141. EmailSendToUsers = config["email_send_to_users"]
  142. // 刷新完成通知邮件人员
  143. RefreshEdbInfoEmailSendToUsers = config["refresh_edb_info_email_send_to_users"]
  144. // 报警服务地址
  145. AlarmMsgUrl = config["alarm_msg_url"]
  146. // 公共指标库相关
  147. {
  148. EDB_LIB_URL = config["edb_lib_url"]
  149. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  150. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  151. }
  152. APPID = config["appid"]
  153. SECRET = config["secret"]
  154. // 商家编码
  155. BusinessCode = config["business_code"]
  156. //服务检测
  157. WindServerUrl = config["wind_server_url"]
  158. LtServerUrl = config["lt_server_url"]
  159. PbServerUrl = config["pb_server_url"]
  160. // ES配置
  161. {
  162. ES_URL = config["es_url"]
  163. ES_USERNAME = config["es_username"]
  164. ES_PASSWORD = config["es_password"]
  165. }
  166. // ES 索引
  167. {
  168. EsReportIndexName = config["es_report_index_name"]
  169. EsEnglishReportIndexName = config["es_english_report_index_name"]
  170. }
  171. // 科大讯飞
  172. {
  173. XfHostUrl = config["xf_host_url"]
  174. }
  175. // OSS相关
  176. {
  177. Endpoint = config["endpoint"]
  178. Bucketname = config["bucket_name"]
  179. Imghost = config["img_host"]
  180. UploadDir = config["upload_dir"]
  181. Upload_Audio_Dir = config["upload_audio_dir"]
  182. AccessKeyId = config["access_key_id"]
  183. AccessKeySecret = config["access_key_secret"]
  184. }
  185. // 微信模版消息
  186. {
  187. SendWxTemplateEnable = config["send_wx_template_enable"]
  188. }
  189. HzDataApi = config["hz_data_api"]
  190. if HzDataApi == "" {
  191. HzDataApi = "https://hzdataapi.hzinsights.com/hzdataapi/"
  192. }
  193. }