Signed-off-by: qudongfang <qudongfang@gmail.com>
| ... | ... |
@@ -108,6 +108,19 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map |
| 108 | 108 |
}, nil |
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 |
+// Close ensures that transport.Client is closed |
|
| 112 |
+// especially needed while using NewClient with *http.Client = nil |
|
| 113 |
+// for example |
|
| 114 |
+// client.NewClient("unix:///var/run/docker.sock", nil, "v1.18", map[string]string{"User-Agent": "engine-api-cli-1.0"})
|
|
| 115 |
+func (cli *Client) Close() error {
|
|
| 116 |
+ |
|
| 117 |
+ if t, ok := cli.client.Transport.(*http.Transport); ok {
|
|
| 118 |
+ t.CloseIdleConnections() |
|
| 119 |
+ } |
|
| 120 |
+ |
|
| 121 |
+ return nil |
|
| 122 |
+} |
|
| 123 |
+ |
|
| 111 | 124 |
// getAPIPath returns the versioned request path to call the api. |
| 112 | 125 |
// It appends the query parameters to the path if they are not empty. |
| 113 | 126 |
func (cli *Client) getAPIPath(p string, query url.Values) string {
|