| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package neero |
||
| 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 | // WithSecretKey sets the secret key to be used for API requests. |
||
| 39 | func WithSecretKey(secretKey string) Option { |
||
| 40 | return clientOptionFunc(func(config *clientConfig) { |
||
| 41 | config.secretKey = secretKey |
||
| 42 | }) |
||
| 44 |