conf.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. // Config defines oss configuration
  14. type Config struct {
  15. Endpoint string // OSS endpoint
  16. AccessKeyID string // AccessId
  17. AccessKeySecret string // AccessKey
  18. RetryTimes uint // Retry count by default it's 5.
  19. UserAgent string // SDK name/version/system information
  20. IsDebug bool // Enable debug mode. Default is false.
  21. Timeout uint // Timeout in seconds. By default it's 60.
  22. SecurityToken string // STS Token
  23. IsCname bool // If cname is in the endpoint.
  24. HTTPTimeout HTTPTimeout // HTTP timeout
  25. IsUseProxy bool // Flag of using proxy.
  26. ProxyHost string // Flag of using proxy host.
  27. IsAuthProxy bool // Flag of needing authentication.
  28. ProxyUser string // Proxy user
  29. ProxyPassword string // Proxy password
  30. IsEnableMD5 bool // Flag of enabling MD5 for upload.
  31. 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.
  32. IsEnableCRC bool // Flag of enabling CRC for upload.
  33. }
  34. // getDefaultOssConfig gets the default configuration.
  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. }