conf.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package oss
  2. import (
  3. "time"
  4. )
  5. // HTTPTimeout defines 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. type HTTPMaxConns struct {
  14. MaxIdleConns int
  15. MaxIdleConnsPerHost int
  16. }
  17. // Config defines oss configuration
  18. type Config struct {
  19. Endpoint string // OSS endpoint
  20. AccessKeyID string // AccessId
  21. AccessKeySecret string // AccessKey
  22. RetryTimes uint // Retry count by default it's 5.
  23. UserAgent string // SDK name/version/system information
  24. IsDebug bool // Enable debug mode. Default is false.
  25. Timeout uint // Timeout in seconds. By default it's 60.
  26. SecurityToken string // STS Token
  27. IsCname bool // If cname is in the endpoint.
  28. HTTPTimeout HTTPTimeout // HTTP timeout
  29. HTTPMaxConns HTTPMaxConns // Http max connections
  30. IsUseProxy bool // Flag of using proxy.
  31. ProxyHost string // Flag of using proxy host.
  32. IsAuthProxy bool // Flag of needing authentication.
  33. ProxyUser string // Proxy user
  34. ProxyPassword string // Proxy password
  35. IsEnableMD5 bool // Flag of enabling MD5 for upload.
  36. MD5Threshold int64 // Memory footprint threshold for each MD5 computation (16MB is the default), in byte. When the data is more than that, temp file is used.
  37. IsEnableCRC bool // Flag of enabling CRC for upload.
  38. }
  39. // getDefaultOssConfig gets the default configuration.
  40. func getDefaultOssConfig() *Config {
  41. config := Config{}
  42. config.Endpoint = ""
  43. config.AccessKeyID = ""
  44. config.AccessKeySecret = ""
  45. config.RetryTimes = 5
  46. config.IsDebug = false
  47. config.UserAgent = userAgent()
  48. config.Timeout = 60 // Seconds
  49. config.SecurityToken = ""
  50. config.IsCname = false
  51. config.HTTPTimeout.ConnectTimeout = time.Second * 30 // 30s
  52. config.HTTPTimeout.ReadWriteTimeout = time.Second * 60 // 60s
  53. config.HTTPTimeout.HeaderTimeout = time.Second * 60 // 60s
  54. config.HTTPTimeout.LongTimeout = time.Second * 300 // 300s
  55. config.HTTPTimeout.IdleConnTimeout = time.Second * 50 // 50s
  56. config.HTTPMaxConns.MaxIdleConns = 100
  57. config.HTTPMaxConns.MaxIdleConnsPerHost = 100
  58. config.IsUseProxy = false
  59. config.ProxyHost = ""
  60. config.IsAuthProxy = false
  61. config.ProxyUser = ""
  62. config.ProxyPassword = ""
  63. config.MD5Threshold = 16 * 1024 * 1024 // 16MB
  64. config.IsEnableMD5 = false
  65. config.IsEnableCRC = true
  66. return &config
  67. }