-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
impr: BKTCLT-35 go client: custom HTTP client
Add the possibility to attach a custom HTTP client to a new instance of BucketClient. The first intended use is to add a timeout to HTTP requests sent by BucketClient.
- Loading branch information
1 parent
da505af
commit c0f1833
Showing
5 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
package bucketclient | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type BucketClient struct { | ||
Endpoint string | ||
Endpoint string | ||
HttpClient *http.Client | ||
} | ||
|
||
func New(bucketdEndpoint string) *BucketClient { | ||
return &BucketClient{bucketdEndpoint} | ||
// New creates a new BucketClient instance, with the provided endpoint (e.g. "localhost:9000"). | ||
// | ||
// If httpClient is non-nil, it uses the provided HTTP client instance, otherwise uses | ||
// `http.DefaultClient`. | ||
func New(bucketdEndpoint string, httpClient *http.Client) *BucketClient { | ||
client := &BucketClient{ | ||
Endpoint: bucketdEndpoint, | ||
} | ||
if httpClient != nil { | ||
client.HttpClient = httpClient | ||
} else { | ||
client.HttpClient = http.DefaultClient | ||
} | ||
return client | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters