Skip to content

Commit

Permalink
allow custom http client (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
thde authored Oct 6, 2020
1 parent 74e4c8e commit 4611975
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 @@ -76,6 +76,13 @@ func WithEndpoint(endpoint string) ClientOption {
}
}

// WithHTTPClient allows to specify a custom http client
func WithHTTPClient(httpClient *http.Client) ClientOption {
return func(client *Client) {
client.httpClient = httpClient
}
}

// WithSkipVerify returns a ClientOption that configure the client connection to not verify https connectins
func WithSkipVerify() ClientOption {
return func(client *Client) {
Expand All @@ -85,14 +92,16 @@ func WithSkipVerify() ClientOption {

// NewClient creates a new client.
func NewClient(options ...ClientOption) *Client {
client := &Client{
httpClient: &http.Client{},
}
client := &Client{}

for _, option := range options {
option(client)
}

if client.httpClient == nil {
client.httpClient = &http.Client{}
}

client.userAgent = userAgent
transCfg := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Expand Down

0 comments on commit 4611975

Please sign in to comment.