Skip to content

Commit

Permalink
Merge pull request #26 from will7200/master
Browse files Browse the repository at this point in the history
feat: allow passing in custom http client
  • Loading branch information
nanmu42 authored May 17, 2021
2 parents 878d197 + 39daf32 commit 3499a85
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 3499a85

Please sign in to comment.