You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by zr...@apache.org on 2022/02/25 23:34:32 UTC
[trafficcontrol] branch master updated: Add the ability to close idle connections to TO Go client (all versions) (#6432)
This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 27d1f70 Add the ability to close idle connections to TO Go client (all versions) (#6432)
27d1f70 is described below
commit 27d1f70302f9ff354ec1197c5a51516124fc14a4
Author: ocket8888 <oc...@apache.org>
AuthorDate: Fri Feb 25 16:34:23 2022 -0700
Add the ability to close idle connections to TO Go client (all versions) (#6432)
(cherry picked from commit 97587b7a293d977c0c4c6d6f2a1efa1edc3da342)
---
traffic_ops/toclientlib/endpoints.go | 16 ++++++++--------
traffic_ops/toclientlib/toclientlib.go | 15 +++++++++++++++
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/traffic_ops/toclientlib/endpoints.go b/traffic_ops/toclientlib/endpoints.go
index d1e8a3a..2846943 100644
--- a/traffic_ops/toclientlib/endpoints.go
+++ b/traffic_ops/toclientlib/endpoints.go
@@ -18,22 +18,22 @@ package toclientlib
const apiBaseStr = "/api/"
// APIBase returns the base API string for HTTP requests, such as /api/3.1.
-func (sn *TOClient) APIBase() string {
- return apiBaseStr + sn.APIVersion()
+func (to *TOClient) APIBase() string {
+ return apiBaseStr + to.APIVersion()
}
// APIVersion is the version of the Traffic Ops API this client will use for requests.
// If the client was created with any function except Login, or with UseLatestSupportedAPI false,
// this will be LatestAPIVersion().
// Otherwise, it will be the version dynamically determined to be the latest the Traffic Ops Server supports.
-func (sn *TOClient) APIVersion() string {
- if sn.latestSupportedAPI != "" {
- return sn.latestSupportedAPI
+func (to *TOClient) APIVersion() string {
+ if to.latestSupportedAPI != "" {
+ return to.latestSupportedAPI
}
- return sn.LatestAPIVersion()
+ return to.LatestAPIVersion()
}
// LatestAPIVersion returns the latest Traffic Ops API version this client supports.
-func (sn *TOClient) LatestAPIVersion() string {
- return sn.apiVersions[0]
+func (to *TOClient) LatestAPIVersion() string {
+ return to.apiVersions[0]
}
diff --git a/traffic_ops/toclientlib/toclientlib.go b/traffic_ops/toclientlib/toclientlib.go
index 6de92da..7cfb4c6 100644
--- a/traffic_ops/toclientlib/toclientlib.go
+++ b/traffic_ops/toclientlib/toclientlib.go
@@ -481,6 +481,21 @@ func NewNoAuthClient(
}, apiVersions)
}
+// Close closes all idle "kept-alive" connections in the client's connection
+// pool. Note that connections in use are unaffected by this call, so it's not
+// necessarily true that calling this method will leave the client with no open
+// connections.
+//
+// This will always return a nil error, the signature is just meant to conform
+// to io.Closer.
+func (to *TOClient) Close() error {
+ if to == nil {
+ return nil
+ }
+ to.Client.CloseIdleConnections()
+ return nil
+}
+
// ErrIsNotImplemented checks that the given error stems from
// ErrNotImplemented.
// Caution: This method does not unwrap errors, and relies on the common