config.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. Re error //redis错误
  14. Rc RedisClient //redis缓存
  15. )
  16. var (
  17. LogPath string //调用过程中的日志存放地址
  18. LogFile string
  19. BinLogPath string //数据库相关的日志存放地址
  20. BinLogFile string
  21. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  22. ApiLogFile string
  23. LogMaxDays int //日志最大保留天数
  24. )
  25. var (
  26. DesKey string // 加密key
  27. EmailSendToUsers string // 邮件提醒人员
  28. BusinessCode string // 商户号
  29. )
  30. var (
  31. EtaPubUrl string
  32. EtaPubAuthorization string
  33. AlarmMsgUrl string
  34. Report2ImgServerUrl string // 报告详情转图片服务地址
  35. ChartLibUrl string
  36. )
  37. var (
  38. ObjectStorageClient string // 目前有oss minio,默认oss
  39. ResourceProxyUrl string // 代理资源地址
  40. )
  41. var (
  42. Bucketname string
  43. Endpoint string
  44. Imghost string
  45. UploadDir string
  46. Upload_Audio_Dir string
  47. AccessKeyId string
  48. AccessKeySecret string
  49. )
  50. var (
  51. MinIoBucketname string
  52. MinIoEndpoint string
  53. MinIoImghost string
  54. MinIoUploadDir string
  55. MinIoUpload_Audio_Dir string
  56. MinIoAccessKeyId string
  57. MinIoAccessKeySecret string
  58. MinIoUseSSL string
  59. MinIoPort string
  60. MinIoRegion string
  61. )
  62. var (
  63. S3Endpoint string
  64. S3BucketName string
  65. S3UploadDir string
  66. S3AccessKeyId string
  67. S3AccessKeySecret string
  68. S3Host string
  69. S3Region string
  70. S3ForceStyle string
  71. S3EndpointPort string
  72. S3Protocol string
  73. S3DisableSSL string
  74. S3OpenAcl string
  75. )
  76. func init() {
  77. tmpRunMode, err := web.AppConfig.String("run_mode")
  78. if err != nil {
  79. panic("配置文件读取run_mode错误 " + err.Error())
  80. }
  81. RunMode = tmpRunMode
  82. if RunMode == "" {
  83. localIp, err := GetLocalIP()
  84. fmt.Println("localIp:", localIp)
  85. if localIp == "10.0.0.123" {
  86. RunMode = "debug"
  87. } else {
  88. RunMode = "release"
  89. }
  90. fmt.Println("RunMode:", RunMode)
  91. configPath := `/home/code/config/eta_gn/eta_report/conf/app.conf`
  92. fmt.Println("configPath:", configPath)
  93. err = web.LoadAppConfig("ini", configPath)
  94. if err != nil {
  95. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  96. }
  97. }
  98. config, err := web.AppConfig.GetSection(RunMode)
  99. if err != nil {
  100. panic("配置文件读取错误 " + err.Error())
  101. }
  102. fmt.Println(RunMode + " 模式")
  103. MYSQL_URL = config["mysql_url"]
  104. MYSQL_URL_ETA = config["mysql_url_eta"]
  105. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  106. REDIS_CACHE = config["beego_cache"]
  107. if len(REDIS_CACHE) <= 0 {
  108. panic(any("redis链接参数没有配置"))
  109. }
  110. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  111. if err != nil {
  112. fmt.Println("redis链接异常:", err)
  113. panic(any(Re))
  114. }
  115. Rc = redisClient
  116. {
  117. LogPath = config["log_path"]
  118. LogFile = config["log_file"]
  119. BinLogPath = config["binlog_path"]
  120. BinLogFile = config["binlog_file"]
  121. ApiLogPath = config["apilog_path"]
  122. ApiLogFile = config["apilog_file"]
  123. logMaxDaysStr := config["log_max_day"]
  124. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  125. }
  126. {
  127. DesKey = config["des_key"]
  128. EmailSendToUsers = config["email_send_to_users"]
  129. BusinessCode = config["business_code"]
  130. }
  131. {
  132. EtaPubUrl = config["eta_pub_url"]
  133. EtaPubAuthorization = config["eta_pub_authorization"]
  134. AlarmMsgUrl = config["alarm_msg_url"]
  135. Report2ImgServerUrl = config["report2img_server_url"]
  136. ChartLibUrl = config["chart_lib_url"]
  137. }
  138. ObjectStorageClient = config["object_storage_client"]
  139. ResourceProxyUrl = config["resource_proxy_url"]
  140. {
  141. Endpoint = config["endpoint"]
  142. Bucketname = config["bucket_name"]
  143. Imghost = config["img_host"]
  144. UploadDir = config["upload_dir"]
  145. Upload_Audio_Dir = config["upload_audio_dir"]
  146. AccessKeyId = config["access_key_id"]
  147. AccessKeySecret = config["access_key_secret"]
  148. }
  149. {
  150. MinIoEndpoint = config["minio_endpoint"]
  151. MinIoBucketname = config["minio_bucket_name"]
  152. MinIoImghost = config["minio_img_host"]
  153. MinIoUploadDir = config["minio_upload_dir"]
  154. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  155. MinIoAccessKeyId = config["minio_access_key_id"]
  156. MinIoAccessKeySecret = config["minio_access_key_secret"]
  157. MinIoUseSSL = config["minio_use_ssl"]
  158. MinIoPort = config["minio_port"]
  159. MinIoRegion = config["minio_region"]
  160. }
  161. {
  162. S3Endpoint = config["s3_endpoint"]
  163. S3BucketName = config["s3_bucket_name"]
  164. S3Host = config["s3_host"]
  165. S3AccessKeyId = config["s3_access_key_id"]
  166. S3AccessKeySecret = config["s3_access_key_secret"]
  167. S3UploadDir = config["s3_upload_dir"]
  168. S3Region = config["s3_region"]
  169. S3ForceStyle = config["s3_force_style"]
  170. S3EndpointPort = config["s3_endpoint_port"]
  171. S3Protocol = config["s3_protocol"]
  172. S3DisableSSL = config["s3_disable_ssl"]
  173. S3OpenAcl = config["s3_open_acl"]
  174. }
  175. }