config.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/server/web"
  5. "strconv"
  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. // 阿里云配置
  51. var (
  52. Bucketname string
  53. Endpoint string
  54. Imghost string
  55. UploadDir string
  56. Upload_Audio_Dir string
  57. AccessKeyId string
  58. AccessKeySecret string
  59. )
  60. // MinIo配置
  61. var (
  62. MinIoBucketname string
  63. MinIoEndpoint string
  64. MinIoImghost string
  65. MinIoUploadDir string
  66. MinIoUpload_Audio_Dir string
  67. MinIoAccessKeyId string
  68. MinIoAccessKeySecret string
  69. MinIoUseSSL string
  70. MinIoPort string
  71. MinIoRegion string
  72. )
  73. // S3配置
  74. var (
  75. S3Endpoint string
  76. S3BucketName string
  77. S3UploadDir string
  78. S3AccessKeyId string
  79. S3AccessKeySecret string
  80. S3Host string
  81. S3Region string
  82. S3ForceStyle string
  83. S3EndpointPort string
  84. S3Protocol string
  85. S3DisableSSL string
  86. S3OpenAcl string
  87. )
  88. func init() {
  89. tmpRunMode, err := web.AppConfig.String("run_mode")
  90. if err != nil {
  91. panic("配置文件读取run_mode错误 " + err.Error())
  92. }
  93. RunMode = tmpRunMode
  94. if RunMode == "" {
  95. localIp, err := GetLocalIP()
  96. fmt.Println("localIp:", localIp)
  97. if localIp == "10.0.0.123" {
  98. RunMode = "debug"
  99. } else {
  100. RunMode = "release"
  101. }
  102. fmt.Println("RunMode:", RunMode)
  103. configPath := `/home/code/config/eta_report/conf/app.conf`
  104. fmt.Println("configPath:", configPath)
  105. err = web.LoadAppConfig("ini", configPath)
  106. if err != nil {
  107. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  108. }
  109. }
  110. config, err := web.AppConfig.GetSection(RunMode)
  111. if err != nil {
  112. panic("配置文件读取错误 " + err.Error())
  113. }
  114. fmt.Println(RunMode + " 模式")
  115. MYSQL_URL = config["mysql_url"]
  116. MYSQL_URL_ETA = config["mysql_url_eta"]
  117. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  118. REDIS_CACHE = config["beego_cache"]
  119. if len(REDIS_CACHE) <= 0 {
  120. panic(any("redis链接参数没有配置"))
  121. }
  122. //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  123. //if Re != nil {
  124. // fmt.Println(Re)
  125. // panic(any(Re))
  126. //}
  127. // 初始化缓存
  128. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  129. if err != nil {
  130. fmt.Println("redis链接异常:", err)
  131. panic(any(Re))
  132. }
  133. Rc = redisClient
  134. //日志配置
  135. {
  136. LogPath = config["log_path"]
  137. LogFile = config["log_file"]
  138. BinLogPath = config["binlog_path"]
  139. BinLogFile = config["binlog_file"]
  140. ApiLogPath = config["apilog_path"]
  141. ApiLogFile = config["apilog_file"]
  142. logMaxDaysStr := config["log_max_day"]
  143. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  144. }
  145. // 系统配置
  146. {
  147. // 接口返回加密KEY
  148. DesKey = config["des_key"]
  149. // 邮件提醒人员
  150. EmailSendToUsers = config["email_send_to_users"]
  151. // 商户号
  152. BusinessCode = config["business_code"]
  153. }
  154. // 系统内部服务地址
  155. {
  156. // 发送微信模板消息地址
  157. EtaPubUrl = config["eta_pub_url"]
  158. // 发送微信模板消息地址
  159. EtaPubAuthorization = config["eta_pub_authorization"]
  160. // 报警服务地址
  161. AlarmMsgUrl = config["alarm_msg_url"]
  162. // 报告详情转图片服务地址
  163. Report2ImgServerUrl = config["report2img_server_url"]
  164. // 图表项目域名
  165. ChartLibUrl = config["chart_lib_url"]
  166. }
  167. // 对象存储客户端
  168. ObjectStorageClient = config["object_storage_client"]
  169. // 代理资源地址
  170. ResourceProxyUrl = config["resource_proxy_url"]
  171. // OSS相关
  172. {
  173. Endpoint = config["endpoint"]
  174. Bucketname = config["bucket_name"]
  175. Imghost = config["img_host"]
  176. UploadDir = config["upload_dir"]
  177. Upload_Audio_Dir = config["upload_audio_dir"]
  178. AccessKeyId = config["access_key_id"]
  179. AccessKeySecret = config["access_key_secret"]
  180. }
  181. // MinIo相关
  182. {
  183. MinIoEndpoint = config["minio_endpoint"]
  184. MinIoBucketname = config["minio_bucket_name"]
  185. MinIoImghost = config["minio_img_host"]
  186. MinIoUploadDir = config["minio_upload_dir"]
  187. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  188. MinIoAccessKeyId = config["minio_access_key_id"]
  189. MinIoAccessKeySecret = config["minio_access_key_secret"]
  190. MinIoUseSSL = config["minio_use_ssl"]
  191. MinIoPort = config["minio_port"]
  192. MinIoRegion = config["minio_region"]
  193. }
  194. // S3-OSS相关
  195. {
  196. S3Endpoint = config["s3_endpoint"]
  197. S3BucketName = config["s3_bucket_name"]
  198. S3Host = config["s3_host"]
  199. S3AccessKeyId = config["s3_access_key_id"]
  200. S3AccessKeySecret = config["s3_access_key_secret"]
  201. S3UploadDir = config["s3_upload_dir"]
  202. S3Region = config["s3_region"]
  203. S3ForceStyle = config["s3_force_style"]
  204. S3EndpointPort = config["s3_endpoint_port"]
  205. S3Protocol = config["s3_protocol"]
  206. S3DisableSSL = config["s3_disable_ssl"]
  207. S3OpenAcl = config["s3_open_acl"]
  208. }
  209. }