-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_option.go
49 lines (41 loc) · 1.26 KB
/
client_option.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
package campay
import (
"net/http"
"strings"
)
// ClientOption are options for constructing a client
type ClientOption interface {
apply(config *clientConfig)
}
type clientOptionFunc func(config *clientConfig)
func (fn clientOptionFunc) apply(config *clientConfig) {
fn(config)
}
// WithHTTPClient sets the underlying HTTP client used for requests.
// By default, http.DefaultClient is used.
func WithHTTPClient(httpClient *http.Client) ClientOption {
return clientOptionFunc(func(config *clientConfig) {
if httpClient != nil {
config.httpClient = httpClient
}
})
}
// WithEnvironment sets the campay endpoint for API requests
// By default, ProdEnvironment is used.
func WithEnvironment(environment Environment) ClientOption {
return clientOptionFunc(func(config *clientConfig) {
config.environment = Environment(strings.TrimRight(environment.String(), "/"))
})
}
// WithAPIUsername sets the campay API username
func WithAPIUsername(apiUsername string) ClientOption {
return clientOptionFunc(func(config *clientConfig) {
config.apiUsername = apiUsername
})
}
// WithAPIPassword sets the campay API password
func WithAPIPassword(apiPassword string) ClientOption {
return clientOptionFunc(func(config *clientConfig) {
config.apiPassword = apiPassword
})
}