From 89f21b2cba4ea0f9cf449b454945f53047697158 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Wed, 4 Sep 2024 23:00:55 +0800 Subject: [PATCH] api: Add ability to CloseIdleConnection for one-off httpClient use cases. (#1513) Signed-off-by: cuisongliu --- api/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/client.go b/api/client.go index 72a0130..afcf122 100644 --- a/api/client.go +++ b/api/client.go @@ -79,6 +79,10 @@ type Client interface { Do(context.Context, *http.Request) (*http.Response, []byte, error) } +type CloseIdler interface { + CloseIdleConnections() +} + // NewClient returns a new Client. // // 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 { return &u } +func (c *httpClient) CloseIdleConnections() { + c.client.CloseIdleConnections() +} + func (c *httpClient) Do(ctx context.Context, req *http.Request) (*http.Response, []byte, error) { if ctx != nil { req = req.WithContext(ctx)