generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_option.go
73 lines (62 loc) · 1.88 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ynote
import (
"net/http"
"strings"
)
// Option is options for constructing a client
type Option 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 API requests.
// By default, http.DefaultClient is used.
func WithHTTPClient(httpClient *http.Client) Option {
return clientOptionFunc(func(config *clientConfig) {
if httpClient != nil {
config.httpClient = httpClient
}
})
}
// WithTokenURL set's the token URL for the Y-Note API
func WithTokenURL(tokenURL string) Option {
return clientOptionFunc(func(config *clientConfig) {
if tokenURL != "" {
config.tokenURL = strings.TrimRight(tokenURL, "/")
}
})
}
// WithAPIURL set's the api URL for the Y-Note API
func WithAPIURL(apiURL string) Option {
return clientOptionFunc(func(config *clientConfig) {
if apiURL != "" {
config.apiURL = strings.TrimRight(apiURL, "/")
}
})
}
// WithClientID sets the Y-Note API clientID used to fetch the access token
func WithClientID(clientID string) Option {
return clientOptionFunc(func(config *clientConfig) {
config.clientID = clientID
})
}
// WithClientSecret sets the Y-Note API client secret used to fetch the access token
func WithClientSecret(clientSecret string) Option {
return clientOptionFunc(func(config *clientConfig) {
config.clientSecret = clientSecret
})
}
// WithCustomerKey sets the customer key used to make API requests
func WithCustomerKey(customerKey string) Option {
return clientOptionFunc(func(config *clientConfig) {
config.customerKey = customerKey
})
}
// WithCustomerSecret sets the customer secret used to make API requests
func WithCustomerSecret(customerSecret string) Option {
return clientOptionFunc(func(config *clientConfig) {
config.customerSecret = customerSecret
})
}