-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader_opts.go
More file actions
40 lines (34 loc) · 921 Bytes
/
Copy pathreader_opts.go
File metadata and controls
40 lines (34 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package httpreader
import "net/http"
type Option func(*Reader) error // functional option pattern
type Options interface {
WithClient(*http.Client) Option
WithHeaders(http.Header) Option
WithDiscard(int) Option
}
func WithClient(client *http.Client) Option {
return func(r *Reader) error {
if client == nil {
client = defaultHTTPClient
}
r.httpClient = client
return nil
}
}
// WithHeaders sets the default HTTP headers that will be sent in all
// requests made by the Reader.
func WithHeaders(header http.Header) Option {
return func(r *Reader) error {
r.httpHeader = header.Clone()
return nil
}
}
// WithDiscard sets the size of the Reader's discard window. When calling
// .Seek() the Reader will try to reuse the HTTP response according the
// value of this parameter.
func WithDiscard(maxDiscard int) Option {
return func(r *Reader) error {
r.discardWnd = maxDiscard
return nil
}
}