Skip to content

Commit

Permalink
feat: allow passing in custom http client
Browse files Browse the repository at this point in the history
  • Loading branch information
will7200 committed May 16, 2021
1 parent 878d197 commit 39daf32
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down

0 comments on commit 39daf32

Please sign in to comment.