config.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. package utils
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/beego/beego/v2/server/web"
  6. )
  7. var (
  8. RunMode string //运行模式
  9. MYSQL_URL string //数据库连接
  10. MYSQL_URL_ETA string
  11. MYSQL_WEEKLY_URL string //CRM主库
  12. REDIS_CACHE string //缓存地址
  13. //Rc *cache.Cache //redis缓存
  14. Re error //redis错误
  15. Rc RedisClient //redis缓存
  16. )
  17. // 日志配置
  18. var (
  19. LogPath string //调用过程中的日志存放地址
  20. LogFile string
  21. BinLogPath string //数据库相关的日志存放地址
  22. BinLogFile string
  23. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  24. ApiLogFile string
  25. LogMaxDays int //日志最大保留天数
  26. )
  27. // 系统配置
  28. var (
  29. DesKey string // 加密key
  30. EmailSendToUsers string // 邮件提醒人员
  31. BusinessCode string // 商户号
  32. )
  33. // 公共api内部服务调用
  34. var (
  35. // EtaPubUrl 模板消息推送
  36. EtaPubUrl string
  37. // EtaPubAuthorization 模板推送秘钥
  38. EtaPubAuthorization string
  39. // AlarmMsgUrl 报警服务地址
  40. AlarmMsgUrl string
  41. Report2ImgServerUrl string // 报告详情转图片服务地址
  42. // ChartLibUrl 图库项目url
  43. ChartLibUrl string
  44. )
  45. // 对象存储客户端
  46. var (
  47. ObjectStorageClient string // 目前有oss minio,默认oss
  48. ResourceProxyUrl string // 代理资源地址
  49. )
  50. var (
  51. StaticDir string //静态文件目录
  52. )
  53. // 阿里云配置
  54. var (
  55. Bucketname string
  56. Endpoint string
  57. Imghost string
  58. UploadDir string
  59. UploadFileDir string
  60. Upload_Audio_Dir string
  61. AccessKeyId string
  62. AccessKeySecret string
  63. )
  64. // MinIo配置
  65. var (
  66. MinIoBucketname string
  67. MinIoEndpoint string
  68. MinIoImghost string
  69. MinIoUploadDir string
  70. MinIoUpload_Audio_Dir string
  71. MinIoAccessKeyId string
  72. MinIoAccessKeySecret string
  73. MinIoUseSSL string
  74. MinIoPort string
  75. MinIoRegion string
  76. )
  77. // S3配置
  78. var (
  79. S3Endpoint string
  80. S3BucketName string
  81. S3UploadDir string
  82. S3AccessKeyId string
  83. S3AccessKeySecret string
  84. S3Host string
  85. S3Region string
  86. S3ForceStyle string
  87. S3EndpointPort string
  88. S3Protocol string
  89. S3DisableSSL string
  90. S3OpenAcl string
  91. )
  92. // ES配置
  93. var (
  94. ES_URL string // ES服务器地址
  95. ES_USERNAME string // ES账号
  96. ES_PASSWORD string // ES密码
  97. )
  98. var (
  99. EsKnowledgeResourceIndexName string //ES知识资源库索引
  100. )
  101. var (
  102. AppId string
  103. Secret string
  104. )
  105. func init() {
  106. tmpRunMode, err := web.AppConfig.String("run_mode")
  107. if err != nil {
  108. panic("配置文件读取run_mode错误 " + err.Error())
  109. }
  110. RunMode = tmpRunMode
  111. if RunMode == "" {
  112. localIp, err := GetLocalIP()
  113. fmt.Println("localIp:", localIp)
  114. if localIp == "10.0.0.123" {
  115. RunMode = "debug"
  116. } else {
  117. RunMode = "release"
  118. }
  119. fmt.Println("RunMode:", RunMode)
  120. configPath := `/home/code/config/eta_gn/eta_report/conf/app.conf`
  121. fmt.Println("configPath:", configPath)
  122. err = web.LoadAppConfig("ini", configPath)
  123. if err != nil {
  124. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  125. }
  126. }
  127. config, err := web.AppConfig.GetSection(RunMode)
  128. if err != nil {
  129. panic("配置文件读取错误 " + err.Error())
  130. }
  131. fmt.Println(RunMode + " 模式")
  132. MYSQL_URL = config["mysql_url"]
  133. MYSQL_URL_ETA = config["mysql_url_eta"]
  134. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  135. REDIS_CACHE = config["beego_cache"]
  136. if len(REDIS_CACHE) <= 0 {
  137. panic(any("redis链接参数没有配置"))
  138. }
  139. //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  140. //if Re != nil {
  141. // fmt.Println(Re)
  142. // panic(any(Re))
  143. //}
  144. // 初始化缓存
  145. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  146. if err != nil {
  147. fmt.Println("redis链接异常:", err)
  148. panic(any(Re))
  149. }
  150. Rc = redisClient
  151. //日志配置
  152. {
  153. LogPath = config["log_path"]
  154. LogFile = config["log_file"]
  155. BinLogPath = config["binlog_path"]
  156. BinLogFile = config["binlog_file"]
  157. ApiLogPath = config["apilog_path"]
  158. ApiLogFile = config["apilog_file"]
  159. logMaxDaysStr := config["log_max_day"]
  160. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  161. }
  162. // 系统配置
  163. {
  164. // 接口返回加密KEY
  165. DesKey = config["des_key"]
  166. // 邮件提醒人员
  167. EmailSendToUsers = config["email_send_to_users"]
  168. // 商户号
  169. BusinessCode = config["business_code"]
  170. }
  171. // 系统内部服务地址
  172. {
  173. // 发送微信模板消息地址
  174. EtaPubUrl = config["eta_pub_url"]
  175. // 发送微信模板消息地址
  176. EtaPubAuthorization = config["eta_pub_authorization"]
  177. // 报警服务地址
  178. AlarmMsgUrl = config["alarm_msg_url"]
  179. // 报告详情转图片服务地址
  180. Report2ImgServerUrl = config["report2img_server_url"]
  181. // 图表项目域名
  182. ChartLibUrl = config["chart_lib_url"]
  183. }
  184. // 对象存储客户端
  185. ObjectStorageClient = config["object_storage_client"]
  186. // 代理资源地址
  187. ResourceProxyUrl = config["resource_proxy_url"]
  188. // 静态资源目录
  189. StaticDir = config["static_dir"]
  190. // OSS相关
  191. {
  192. Endpoint = config["endpoint"]
  193. Bucketname = config["bucket_name"]
  194. Imghost = config["img_host"]
  195. UploadDir = config["upload_dir"]
  196. UploadFileDir = config["upload_file_dir"]
  197. Upload_Audio_Dir = config["upload_audio_dir"]
  198. AccessKeyId = config["access_key_id"]
  199. AccessKeySecret = config["access_key_secret"]
  200. }
  201. // MinIo相关
  202. {
  203. MinIoEndpoint = config["minio_endpoint"]
  204. MinIoBucketname = config["minio_bucket_name"]
  205. MinIoImghost = config["minio_img_host"]
  206. MinIoUploadDir = config["minio_upload_dir"]
  207. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  208. MinIoAccessKeyId = config["minio_access_key_id"]
  209. MinIoAccessKeySecret = config["minio_access_key_secret"]
  210. MinIoUseSSL = config["minio_use_ssl"]
  211. MinIoPort = config["minio_port"]
  212. MinIoRegion = config["minio_region"]
  213. }
  214. // S3-OSS相关
  215. {
  216. S3Endpoint = config["s3_endpoint"]
  217. S3BucketName = config["s3_bucket_name"]
  218. S3Host = config["s3_host"]
  219. S3AccessKeyId = config["s3_access_key_id"]
  220. S3AccessKeySecret = config["s3_access_key_secret"]
  221. S3UploadDir = config["s3_upload_dir"]
  222. S3Region = config["s3_region"]
  223. S3ForceStyle = config["s3_force_style"]
  224. S3EndpointPort = config["s3_endpoint_port"]
  225. S3Protocol = config["s3_protocol"]
  226. S3DisableSSL = config["s3_disable_ssl"]
  227. S3OpenAcl = config["s3_open_acl"]
  228. }
  229. // ES配置
  230. {
  231. ES_URL = config["es_url"]
  232. ES_USERNAME = config["es_username"]
  233. ES_PASSWORD = config["es_password"]
  234. }
  235. {
  236. // ES知识资源库索引
  237. EsKnowledgeResourceIndexName = config["es_knowledge_resource_index_name"]
  238. }
  239. AppId = config["appid"]
  240. Secret = config["secret"]
  241. initEs()
  242. }