Skip to content

Commit 1595805

Browse files
committed
cli/context/docker: Endpoint.ClientOpts: inline withHTTPClient
Inline the wrapper "option", as the signature for ClientOpts may not be implementable in future (possibly we need to change this); #18 16.94 # github.com/docker/cli/cli/context/docker #18 16.94 cli/context/docker/load.go:105:29: cannot use withHTTPClient(tlsConfig) (value of type func(*client.Client) error) as client.Opt value in argument to append #18 16.94 cli/context/docker/load.go:152:6: cannot use c (variable of type *client.Client) as *client.clientConfig value in argument to client.WithHTTPClient(&http.Client{…}) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 27b316f commit 1595805

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

cli/context/docker/load.go

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,20 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
102102
if err != nil {
103103
return nil, err
104104
}
105-
result = append(result, withHTTPClient(tlsConfig))
105+
if tlsConfig != nil {
106+
result = append(result,
107+
client.WithHTTPClient(&http.Client{
108+
Transport: &http.Transport{
109+
TLSClientConfig: tlsConfig,
110+
DialContext: (&net.Dialer{
111+
KeepAlive: 30 * time.Second,
112+
Timeout: 30 * time.Second,
113+
}).DialContext,
114+
},
115+
CheckRedirect: client.CheckRedirect,
116+
}),
117+
)
118+
}
106119
}
107120
result = append(result, client.WithHost(ep.Host))
108121
} else {
@@ -134,25 +147,6 @@ func isSocket(addr string) bool {
134147
}
135148
}
136149

137-
func withHTTPClient(tlsConfig *tls.Config) func(*client.Client) error {
138-
return func(c *client.Client) error {
139-
if tlsConfig == nil {
140-
// Use the default HTTPClient
141-
return nil
142-
}
143-
return client.WithHTTPClient(&http.Client{
144-
Transport: &http.Transport{
145-
TLSClientConfig: tlsConfig,
146-
DialContext: (&net.Dialer{
147-
KeepAlive: 30 * time.Second,
148-
Timeout: 30 * time.Second,
149-
}).DialContext,
150-
},
151-
CheckRedirect: client.CheckRedirect,
152-
})(c)
153-
}
154-
}
155-
156150
// EndpointFromContext parses a context docker endpoint metadata into a typed EndpointMeta structure
157151
func EndpointFromContext(metadata store.Metadata) (EndpointMeta, error) {
158152
ep, ok := metadata.Endpoints[DockerEndpoint]

0 commit comments

Comments
 (0)