conf.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package oss
  2. import (
  3. "time"
  4. )
  5. // HTTPTimeout http timeout
  6. type HTTPTimeout struct {
  7. ConnectTimeout time.Duration
  8. ReadWriteTimeout time.Duration
  9. HeaderTimeout time.Duration
  10. LongTimeout time.Duration
  11. }
  12. // Config oss configure
  13. type Config struct {
  14. Endpoint string // oss地址
  15. AccessKeyID string // accessId
  16. AccessKeySecret string // accessKey
  17. RetryTimes uint // 失败重试次数,默认5
  18. UserAgent string // SDK名称/版本/系统信息
  19. IsDebug bool // 是否开启调试模式,默认false
  20. Timeout uint // 超时时间,默认60s
  21. SecurityToken string // STS Token
  22. IsCname bool // Endpoint是否是CNAME
  23. HTTPTimeout HTTPTimeout // HTTP的超时时间设置
  24. IsUseProxy bool // 是否使用代理
  25. ProxyHost string // 代理服务器地址
  26. IsAuthProxy bool // 代理服务器是否使用用户认证
  27. ProxyUser string // 代理服务器认证用户名
  28. ProxyPassword string // 代理服务器认证密码
  29. IsEnableMD5 bool // 上传数据时是否启用MD5校验
  30. MD5Threshold int64 // 内存中计算MD5的上线大小,大于该值启用临时文件,单位Byte
  31. IsEnableCRC bool // 上传数据时是否启用CRC64校验
  32. }
  33. // 获取默认配置
  34. func getDefaultOssConfig() *Config {
  35. config := Config{}
  36. config.Endpoint = ""
  37. config.AccessKeyID = ""
  38. config.AccessKeySecret = ""
  39. config.RetryTimes = 5
  40. config.IsDebug = false
  41. config.UserAgent = userAgent
  42. config.Timeout = 60 // seconds
  43. config.SecurityToken = ""
  44. config.IsCname = false
  45. config.HTTPTimeout.ConnectTimeout = time.Second * 30 // 30s
  46. config.HTTPTimeout.ReadWriteTimeout = time.Second * 60 // 60s
  47. config.HTTPTimeout.HeaderTimeout = time.Second * 60 // 60s
  48. config.HTTPTimeout.LongTimeout = time.Second * 300 // 300s
  49. config.IsUseProxy = false
  50. config.ProxyHost = ""
  51. config.IsAuthProxy = false
  52. config.ProxyUser = ""
  53. config.ProxyPassword = ""
  54. config.MD5Threshold = 16 * 1024 * 1024 // 16MB
  55. config.IsEnableMD5 = false
  56. config.IsEnableCRC = true
  57. return &config
  58. }