conf.go 2.2 KB

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