From 4611975f7134eed1d54fa5103ed0eebd4f384a20 Mon Sep 17 00:00:00 2001 From: Demian Date: Tue, 6 Oct 2020 18:03:42 +0200 Subject: [PATCH] allow custom http client (#10) --- client.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index c336e80..d1a6233 100644 --- a/client.go +++ b/client.go @@ -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) { @@ -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,