config.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. var (
  89. AppId string
  90. Secret string
  91. )
  92. func init() {
  93. tmpRunMode, err := web.AppConfig.String("run_mode")
  94. if err != nil {
  95. panic("配置文件读取run_mode错误 " + err.Error())
  96. }
  97. RunMode = tmpRunMode
  98. if RunMode == "" {
  99. localIp, err := GetLocalIP()
  100. fmt.Println("localIp:", localIp)
  101. if localIp == "10.0.0.123" {
  102. RunMode = "debug"
  103. } else {
  104. RunMode = "release"
  105. }
  106. fmt.Println("RunMode:", RunMode)
  107. configPath := `/home/code/config/eta_gn/eta_report/conf/app.conf`
  108. fmt.Println("configPath:", configPath)
  109. err = web.LoadAppConfig("ini", configPath)
  110. if err != nil {
  111. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  112. }
  113. }
  114. config, err := web.AppConfig.GetSection(RunMode)
  115. if err != nil {
  116. panic("配置文件读取错误 " + err.Error())
  117. }
  118. fmt.Println(RunMode + " 模式")
  119. MYSQL_URL = config["mysql_url"]
  120. MYSQL_URL_ETA = config["mysql_url_eta"]
  121. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  122. REDIS_CACHE = config["beego_cache"]
  123. if len(REDIS_CACHE) <= 0 {
  124. panic(any("redis链接参数没有配置"))
  125. }
  126. //Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  127. //if Re != nil {
  128. // fmt.Println(Re)
  129. // panic(any(Re))
  130. //}
  131. // 初始化缓存
  132. redisClient, err := initRedis(config["redis_type"], config["beego_cache"])
  133. if err != nil {
  134. fmt.Println("redis链接异常:", err)
  135. panic(any(Re))
  136. }
  137. Rc = redisClient
  138. //日志配置
  139. {
  140. LogPath = config["log_path"]
  141. LogFile = config["log_file"]
  142. BinLogPath = config["binlog_path"]
  143. BinLogFile = config["binlog_file"]
  144. ApiLogPath = config["apilog_path"]
  145. ApiLogFile = config["apilog_file"]
  146. logMaxDaysStr := config["log_max_day"]
  147. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  148. }
  149. // 系统配置
  150. {
  151. // 接口返回加密KEY
  152. DesKey = config["des_key"]
  153. // 邮件提醒人员
  154. EmailSendToUsers = config["email_send_to_users"]
  155. // 商户号
  156. BusinessCode = config["business_code"]
  157. }
  158. // 系统内部服务地址
  159. {
  160. // 发送微信模板消息地址
  161. EtaPubUrl = config["eta_pub_url"]
  162. // 发送微信模板消息地址
  163. EtaPubAuthorization = config["eta_pub_authorization"]
  164. // 报警服务地址
  165. AlarmMsgUrl = config["alarm_msg_url"]
  166. // 报告详情转图片服务地址
  167. Report2ImgServerUrl = config["report2img_server_url"]
  168. // 图表项目域名
  169. ChartLibUrl = config["chart_lib_url"]
  170. }
  171. // 对象存储客户端
  172. ObjectStorageClient = config["object_storage_client"]
  173. // 代理资源地址
  174. ResourceProxyUrl = config["resource_proxy_url"]
  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. // MinIo相关
  186. {
  187. MinIoEndpoint = config["minio_endpoint"]
  188. MinIoBucketname = config["minio_bucket_name"]
  189. MinIoImghost = config["minio_img_host"]
  190. MinIoUploadDir = config["minio_upload_dir"]
  191. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  192. MinIoAccessKeyId = config["minio_access_key_id"]
  193. MinIoAccessKeySecret = config["minio_access_key_secret"]
  194. MinIoUseSSL = config["minio_use_ssl"]
  195. MinIoPort = config["minio_port"]
  196. MinIoRegion = config["minio_region"]
  197. }
  198. // S3-OSS相关
  199. {
  200. S3Endpoint = config["s3_endpoint"]
  201. S3BucketName = config["s3_bucket_name"]
  202. S3Host = config["s3_host"]
  203. S3AccessKeyId = config["s3_access_key_id"]
  204. S3AccessKeySecret = config["s3_access_key_secret"]
  205. S3UploadDir = config["s3_upload_dir"]
  206. S3Region = config["s3_region"]
  207. S3ForceStyle = config["s3_force_style"]
  208. S3EndpointPort = config["s3_endpoint_port"]
  209. S3Protocol = config["s3_protocol"]
  210. S3DisableSSL = config["s3_disable_ssl"]
  211. S3OpenAcl = config["s3_open_acl"]
  212. }
  213. AppId = config["appid"]
  214. Secret = config["secret"]
  215. }