Skip to content

Commit

Permalink
Refactor base method to make it become reusable whenever it's needed
Browse files Browse the repository at this point in the history
  • Loading branch information
denismakogon committed Jan 21, 2018
1 parent a8f5e91 commit c13236a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
9 changes: 4 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,12 @@ func NewVersionedClient(endpoint string, apiVersionString string) (*Client, erro
eventMonitor: new(eventMonitoringState),
requestedAPIVersion: requestedAPIVersion,
}
c.initializeNativeClient()
initializeNativeClient(c, defaultTransport)
return c, nil
}

func (c *Client) WithTransport(tr *http.Transport) {
initializeNativeClientTransport(c, tr)
c.HTTPClient.Transport = tr
func (c *Client) WithTransport(trFunc func () *http.Transport) {
initializeNativeClient(c, trFunc)
}

// NewVersionnedTLSClient has been DEPRECATED, please use NewVersionedTLSClient.
Expand Down Expand Up @@ -344,7 +343,7 @@ func NewVersionedTLSClientFromBytes(endpoint string, certPEMBlock, keyPEMBlock,
eventMonitor: new(eventMonitoringState),
requestedAPIVersion: requestedAPIVersion,
}
c.initializeNativeClient()
initializeNativeClient(c, defaultTransport)
return c, nil
}

Expand Down
10 changes: 4 additions & 6 deletions client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ import (

// initializeNativeClient initializes the native Unix domain socket client on
// Unix-style operating systems
func (c *Client) initializeNativeClient() {
func initializeNativeClient(c *Client, trFunc func () *http.Transport) {
if c.endpointURL.Scheme != unixProtocol {
return
}
tr := defaultTransport()
initializeNativeClientTransport(c, tr)
}

func initializeNativeClientTransport(c *Client, tr *http.Transport) {
sockPath := c.endpointURL.Path

tr := trFunc()

tr.Dial = func(network, addr string) (net.Conn, error) {
return c.Dialer.Dial(unixProtocol, sockPath)
}
Expand Down

0 comments on commit c13236a

Please sign in to comment.