1// +build integration,perftest 2 3package downloader 4 5import ( 6 "flag" 7 "net/http" 8 "strings" 9 "time" 10 11 "github.com/aws/aws-sdk-go-v2/feature/s3/manager" 12) 13 14type SDKConfig struct { 15 PartSize int64 16 Concurrency int 17 BufferProvider manager.WriterReadFromProvider 18} 19 20func (c *SDKConfig) SetupFlags(prefix string, flagset *flag.FlagSet) { 21 prefix += "sdk." 22 23 flagset.Int64Var(&c.PartSize, prefix+"part-size", manager.DefaultDownloadPartSize, 24 "Specifies the `size` of parts of the object to download.") 25 flagset.IntVar(&c.Concurrency, prefix+"concurrency", manager.DefaultDownloadConcurrency, 26 "Specifies the number of parts to download `at once`.") 27} 28 29func (c *SDKConfig) Validate() error { 30 return nil 31} 32 33type ClientConfig struct { 34 KeepAlive bool 35 Timeouts Timeouts 36 37 MaxIdleConns int 38 MaxIdleConnsPerHost int 39 40 // Go 1.13 41 ReadBufferSize int 42 WriteBufferSize int 43} 44 45func (c *ClientConfig) SetupFlags(prefix string, flagset *flag.FlagSet) { 46 prefix += "client." 47 48 flagset.BoolVar(&c.KeepAlive, prefix+"http-keep-alive", true, 49 "Specifies if HTTP keep alive is enabled.") 50 51 defTR := http.DefaultTransport.(*http.Transport) 52 53 flagset.IntVar(&c.MaxIdleConns, prefix+"idle-conns", defTR.MaxIdleConns, 54 "Specifies max idle connection pool size.") 55 56 flagset.IntVar(&c.MaxIdleConnsPerHost, prefix+"idle-conns-host", http.DefaultMaxIdleConnsPerHost, 57 "Specifies max idle connection pool per host, will be truncated by idle-conns.") 58 59 flagset.IntVar(&c.ReadBufferSize, prefix+"read-buffer", defTR.ReadBufferSize, "size of the transport read buffer used") 60 flagset.IntVar(&c.WriteBufferSize, prefix+"writer-buffer", defTR.WriteBufferSize, "size of the transport write buffer used") 61 62 c.Timeouts.SetupFlags(prefix, flagset) 63} 64 65func (c *ClientConfig) Validate() error { 66 var errs Errors 67 68 if err := c.Timeouts.Validate(); err != nil { 69 errs = append(errs, err) 70 } 71 72 if len(errs) != 0 { 73 return errs 74 } 75 return nil 76} 77 78type Timeouts struct { 79 Connect time.Duration 80 TLSHandshake time.Duration 81 ExpectContinue time.Duration 82 ResponseHeader time.Duration 83} 84 85func (c *Timeouts) SetupFlags(prefix string, flagset *flag.FlagSet) { 86 prefix += "timeout." 87 88 flagset.DurationVar(&c.Connect, prefix+"connect", 30*time.Second, 89 "The `timeout` connecting to the remote host.") 90 91 defTR := http.DefaultTransport.(*http.Transport) 92 93 flagset.DurationVar(&c.TLSHandshake, prefix+"tls", defTR.TLSHandshakeTimeout, 94 "The `timeout` waiting for the TLS handshake to complete.") 95 96 flagset.DurationVar(&c.ExpectContinue, prefix+"expect-continue", defTR.ExpectContinueTimeout, 97 "The `timeout` waiting for the TLS handshake to complete.") 98 99 flagset.DurationVar(&c.ResponseHeader, prefix+"response-header", defTR.ResponseHeaderTimeout, 100 "The `timeout` waiting for the TLS handshake to complete.") 101} 102 103func (c *Timeouts) Validate() error { 104 return nil 105} 106 107type Errors []error 108 109func (es Errors) Error() string { 110 var buf strings.Builder 111 for _, e := range es { 112 buf.WriteString(e.Error()) 113 } 114 115 return buf.String() 116} 117