-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
55 lines (48 loc) · 1.38 KB
/
options.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package httpc
// ClientOptFn sets keys on a client type.
type ClientOptFn func(Client) Client
// WithAuth sets the authorization func on the client type,
// and will be used as the default authFn for all requests
// from this client unless overwritten atn the request lvl.
func WithAuth(authFn AuthFn) ClientOptFn {
return func(c Client) Client {
c.authFn = authFn
return c
}
}
// WithBackoff sets teh backoff on the client.
func WithBackoff(b BackoffOptFn) ClientOptFn {
return func(c Client) Client {
c.backoff = b
return c
}
}
// WithBaseURL sets teh base url for all requests. Any path provided will be
// appended to this WithBaseURL.
func WithBaseURL(baseURL string) ClientOptFn {
return func(c Client) Client {
c.baseURL = baseURL
return c
}
}
// WithContentType sets content type that will be applied to all requests.
func WithContentType(cType string) ClientOptFn {
return func(c Client) Client {
c.headers = append(c.headers, kvPair{key: "Content-Type", value: cType})
return c
}
}
// WithEncoder sets the encode func for the client.
func WithEncoder(fn EncodeFn) ClientOptFn {
return func(c Client) Client {
c.encodeFn = fn
return c
}
}
// WithHeader sets headers that will be applied to all requests.
func WithHeader(key, value string) ClientOptFn {
return func(c Client) Client {
c.headers = append(c.headers, kvPair{key: key, value: value})
return c
}
}