From 39daf32d6557c767a307a2215de4fd763200b34b Mon Sep 17 00:00:00 2001 From: William Flores Date: Sun, 16 May 2021 15:53:34 -0700 Subject: [PATCH] feat: allow passing in custom http client --- client.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 9654538..e69679a 100644 --- a/client.go +++ b/client.go @@ -57,6 +57,9 @@ type Customization struct { BaseURL string // When true, talks a lot Verbose bool + // HTTP Client to be used. Specifying this value will ignore the Timeout value set + // Set your own timeout. + Client *http.Client // BeforeRequest runs before every client request, in the same goroutine. // May be used in rate limit. @@ -70,10 +73,16 @@ type Customization struct { // NewCustomized initialize a customized API client, // useful when calling against etherscan-family API like BscScan. func NewCustomized(config Customization) *Client { - return &Client{ - coon: &http.Client{ + var httpClient *http.Client + if config.Client != nil { + httpClient = config.Client + } else { + httpClient = &http.Client{ Timeout: config.Timeout, - }, + } + } + return &Client{ + coon: httpClient, key: config.Key, baseURL: config.BaseURL, Verbose: config.Verbose,