From 1ee73b132485dbdcfd7c7ffb9f517cd9cda6ee6b Mon Sep 17 00:00:00 2001 From: Eliise S Date: Thu, 9 Jan 2020 10:12:41 +0000 Subject: [PATCH] Use global httpclient --- aws/client.go | 1 + azure/client.go | 1 + databricks.go | 11 ++++++++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aws/client.go b/aws/client.go index df96492..777fc52 100644 --- a/aws/client.go +++ b/aws/client.go @@ -10,6 +10,7 @@ type DBClient struct { // Init initializes the client func (c *DBClient) Init(option databricks.DBClientOption) DBClient { c.Option = option + option.Init() return *c } diff --git a/azure/client.go b/azure/client.go index 63333c6..621e4b3 100644 --- a/azure/client.go +++ b/azure/client.go @@ -10,6 +10,7 @@ type DBClient struct { // Init initializes the client func (c *DBClient) Init(option databricks.DBClientOption) DBClient { c.Option = option + option.Init() return *c } diff --git a/databricks.go b/databricks.go index 7e1fc6c..9fb62af 100644 --- a/databricks.go +++ b/databricks.go @@ -18,13 +18,15 @@ type DBClientOption struct { DefaultHeaders map[string]string InsecureSkipVerify bool TimeoutSeconds int + client http.Client } -func (o *DBClientOption) getHTTPClient() http.Client { +// Init initializes the client +func (o *DBClientOption) Init() { if o.TimeoutSeconds == 0 { o.TimeoutSeconds = 10 } - client := http.Client{ + o.client = http.Client{ Timeout: time.Duration(time.Duration(o.TimeoutSeconds) * time.Second), Transport: &http.Transport{ TLSClientConfig: &tls.Config{ @@ -32,7 +34,10 @@ func (o *DBClientOption) getHTTPClient() http.Client { }, }, } - return client +} + +func (o *DBClientOption) getHTTPClient() http.Client { + return o.client } func (o *DBClientOption) getAuthHeader() map[string]string {