Skip to content

Commit 39daf32

Browse files
committed
feat: allow passing in custom http client
1 parent 878d197 commit 39daf32

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

client.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ type Customization struct {
5757
BaseURL string
5858
// When true, talks a lot
5959
Verbose bool
60+
// HTTP Client to be used. Specifying this value will ignore the Timeout value set
61+
// Set your own timeout.
62+
Client *http.Client
6063

6164
// BeforeRequest runs before every client request, in the same goroutine.
6265
// May be used in rate limit.
@@ -70,10 +73,16 @@ type Customization struct {
7073
// NewCustomized initialize a customized API client,
7174
// useful when calling against etherscan-family API like BscScan.
7275
func NewCustomized(config Customization) *Client {
73-
return &Client{
74-
coon: &http.Client{
76+
var httpClient *http.Client
77+
if config.Client != nil {
78+
httpClient = config.Client
79+
} else {
80+
httpClient = &http.Client{
7581
Timeout: config.Timeout,
76-
},
82+
}
83+
}
84+
return &Client{
85+
coon: httpClient,
7786
key: config.Key,
7887
baseURL: config.BaseURL,
7988
Verbose: config.Verbose,

0 commit comments

Comments
 (0)