config.go 5.6 KB

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