Skip to content

Commit 89f21b2

Browse files
authored
api: Add ability to CloseIdleConnection for one-off httpClient use cases. (#1513)
Signed-off-by: cuisongliu <cuisongliu@qq.com>
1 parent a5e1340 commit 89f21b2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

api/client.go

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ type Client interface {
7979
Do(context.Context, *http.Request) (*http.Response, []byte, error)
8080
}
8181

82+
type CloseIdler interface {
83+
CloseIdleConnections()
84+
}
85+
8286
// NewClient returns a new Client.
8387
//
8488
// It is safe to use the returned Client from multiple goroutines.
@@ -118,6 +122,10 @@ func (c *httpClient) URL(ep string, args map[string]string) *url.URL {
118122
return &u
119123
}
120124

125+
func (c *httpClient) CloseIdleConnections() {
126+
c.client.CloseIdleConnections()
127+
}
128+
121129
func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) {
122130
if ctx != nil {
123131
req = req.WithContext(ctx)

0 commit comments

Comments
 (0)