Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package client |
||
2 | |||
3 | import ( |
||
4 | "net/http" |
||
5 | "strings" |
||
6 | ) |
||
7 | |||
8 | // Option is options for constructing a client |
||
9 | type Option interface { |
||
10 | apply(config *clientConfig) |
||
11 | } |
||
12 | |||
13 | type clientOptionFunc func(config *clientConfig) |
||
14 | |||
15 | func (fn clientOptionFunc) apply(config *clientConfig) { |
||
16 | fn(config) |
||
17 | } |
||
18 | |||
19 | // WithHTTPClient sets the underlying HTTP client used for API requests. |
||
20 | // By default, http.DefaultClient is used. |
||
21 | func WithHTTPClient(httpClient *http.Client) Option { |
||
22 | return clientOptionFunc(func(config *clientConfig) { |
||
23 | if httpClient != nil { |
||
24 | config.httpClient = httpClient |
||
25 | } |
||
26 | }) |
||
27 | } |
||
28 | |||
29 | // WithBaseURL set's the base url for the flutterwave API |
||
30 | func WithBaseURL(baseURL string) Option { |
||
31 | return clientOptionFunc(func(config *clientConfig) { |
||
32 | if baseURL != "" { |
||
33 | config.baseURL = strings.TrimRight(baseURL, "/") |
||
34 | } |
||
35 | }) |
||
36 | } |
||
37 | |||
38 | // WithDelay sets the delay in milliseconds before a response is gotten. |
||
39 | // The delay must be > 0 for it to be used. |
||
40 | func WithDelay(delay int) Option { |
||
41 | return clientOptionFunc(func(config *clientConfig) { |
||
42 | if delay > 0 { |
||
43 | config.delay = delay |
||
44 | } |
||
47 |