flutterwave.clientOptionFunc.apply   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
nop 1
1
package flutterwave
2
3
import (
4
	"net/http"
5
	"strings"
6
)
7
8
// ClientOption are options for constructing a client
9
type ClientOption 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) ClientOption {
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) ClientOption {
31
	return clientOptionFunc(func(config *clientConfig) {
32
		if baseURL != "" {
33
			config.baseURL = strings.TrimRight(baseURL, "/")
34
		}
35
	})
36
}
37
38
// WithSecretKey set's the secret key used to authorize requests to the flutterwave API
39
// See: https://developer.flutterwave.com/docs/api-keys
40
func WithSecretKey(secretKey string) ClientOption {
41
	return clientOptionFunc(func(config *clientConfig) {
42
		config.secretKey = secretKey
43
	})
44
}
45