-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_option.go
46 lines (39 loc) · 1.04 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
package client
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
}
})
}
// WithBaseURL set's the base url for the flutterwave API
func WithBaseURL(baseURL string) Option {
return clientOptionFunc(func(config *clientConfig) {
if baseURL != "" {
config.baseURL = strings.TrimRight(baseURL, "/")
}
})
}
// WithDelay sets the delay in milliseconds before a response is gotten.
// The delay must be > 0 for it to be used.
func WithDelay(delay int) Option {
return clientOptionFunc(func(config *clientConfig) {
if delay > 0 {
config.delay = delay
}
})
}