Skip to content

Commit c13236a

Browse files
committed
Refactor base method to make it become reusable whenever it's needed
1 parent a8f5e91 commit c13236a

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

client.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
218218
eventMonitor: new(eventMonitoringState),
219219
requestedAPIVersion: requestedAPIVersion,
220220
}
221-
c.initializeNativeClient()
221+
initializeNativeClient(c, defaultTransport)
222222
return c, nil
223223
}
224224

225-
func (c *Client) WithTransport(tr *http.Transport) {
226-
initializeNativeClientTransport(c, tr)
227-
c.HTTPClient.Transport = tr
225+
func (c *Client) WithTransport(trFunc func () *http.Transport) {
226+
initializeNativeClient(c, trFunc)
228227
}
229228

230229
// NewVersionnedTLSClient has been DEPRECATED, please use NewVersionedTLSClient.
@@ -344,7 +343,7 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
344343
eventMonitor: new(eventMonitoringState),
345344
requestedAPIVersion: requestedAPIVersion,
346345
}
347-
c.initializeNativeClient()
346+
initializeNativeClient(c, defaultTransport)
348347
return c, nil
349348
}
350349

client_unix.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ import (
1414

1515
// initializeNativeClient initializes the native Unix domain socket client on
1616
// Unix-style operating systems
17-
func (c *Client) initializeNativeClient() {
17+
func initializeNativeClient(c *Client, trFunc func () *http.Transport) {
1818
if c.endpointURL.Scheme != unixProtocol {
1919
return
2020
}
21-
tr := defaultTransport()
22-
initializeNativeClientTransport(c, tr)
23-
}
24-
25-
func initializeNativeClientTransport(c *Client, tr *http.Transport) {
2621
sockPath := c.endpointURL.Path
22+
23+
tr := trFunc()
24+
2725
tr.Dial = func(network, addr string) (net.Conn, error) {
2826
return c.Dialer.Dial(unixProtocol, sockPath)
2927
}

0 commit comments

Comments
 (0)