conf.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. IsEnableMD5 bool // 上传数据时是否启用MD5校验
  25. IsUseProxy bool // 是否使用代理
  26. ProxyHost string // 代理服务器地址
  27. IsAuthProxy bool // 代理服务器是否使用用户认证
  28. ProxyUser string // 代理服务器认证用户名
  29. ProxyPassword string // 代理服务器认证密码
  30. }
  31. // 获取默认配置
  32. func getDefaultOssConfig() *Config {
  33. config := Config{}
  34. config.Endpoint = ""
  35. config.AccessKeyID = ""
  36. config.AccessKeySecret = ""
  37. config.RetryTimes = 5
  38. config.IsDebug = false
  39. config.UserAgent = userAgent
  40. config.Timeout = 60 // seconds
  41. config.SecurityToken = ""
  42. config.IsCname = false
  43. config.IsEnableMD5 = true
  44. config.HTTPTimeout.ConnectTimeout = time.Second * 30 // 30s
  45. config.HTTPTimeout.ReadWriteTimeout = time.Second * 60 // 60s
  46. config.HTTPTimeout.HeaderTimeout = time.Second * 60 // 60s
  47. config.HTTPTimeout.LongTimeout = time.Second * 300 // 300s
  48. config.IsUseProxy = false
  49. config.ProxyHost = ""
  50. config.IsAuthProxy = false
  51. config.ProxyUser = ""
  52. config.ProxyPassword = ""
  53. return &config
  54. }