| ... | ... |
@@ -168,6 +168,19 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map |
| 168 | 168 |
}, nil |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 |
+// Close ensures that transport.Client is closed |
|
| 172 |
+// especially needed while using NewClient with *http.Client = nil |
|
| 173 |
+// for example |
|
| 174 |
+// client.NewClient("unix:///var/run/docker.sock", nil, "v1.18", map[string]string{"User-Agent": "engine-api-cli-1.0"})
|
|
| 175 |
+func (cli *Client) Close() error {
|
|
| 176 |
+ |
|
| 177 |
+ if t, ok := cli.client.Transport.(*http.Transport); ok {
|
|
| 178 |
+ t.CloseIdleConnections() |
|
| 179 |
+ } |
|
| 180 |
+ |
|
| 181 |
+ return nil |
|
| 182 |
+} |
|
| 183 |
+ |
|
| 171 | 184 |
// getAPIPath returns the versioned request path to call the api. |
| 172 | 185 |
// It appends the query parameters to the path if they are not empty. |
| 173 | 186 |
func (cli *Client) getAPIPath(p string, query url.Values) string {
|