From 53b3842e293c1e1554d2126078eb8a60a00e9a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Tue, 13 Jul 2021 17:16:13 +0200 Subject: [PATCH] rgw/admin: add an interface around the HTTP Client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now have a new interface `HTTPClient` which helps us doing various operations such as mutating and mocking the HTTP Client. Signed-off-by: Sébastien Han --- rgw/admin/radosgw.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rgw/admin/radosgw.go b/rgw/admin/radosgw.go index 006f895..e58827d 100644 --- a/rgw/admin/radosgw.go +++ b/rgw/admin/radosgw.go @@ -28,6 +28,11 @@ var ( errNoSecretKey = errors.New("secret key not set") ) +// HTTPClient interface that conforms to that of the http package's Client. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) +} + type verbHTTP string // API struct for New Client @@ -35,12 +40,12 @@ type API struct { AccessKey string SecretKey string Endpoint string - HTTPClient *http.Client + HTTPClient HTTPClient Debug bool } // New returns client for Ceph RGW -func New(endpoint, accessKey, secretKey string, httpClient *http.Client) (*API, error) { +func New(endpoint, accessKey, secretKey string, httpClient HTTPClient) (*API, error) { // validate endpoint if endpoint == "" { return nil, errNoEndpoint @@ -56,7 +61,7 @@ func New(endpoint, accessKey, secretKey string, httpClient *http.Client) (*API, return nil, errNoSecretKey } - // set http client, if TLS is desired it will have to be passed with an http client + // If no client is passed initialize it if httpClient == nil { httpClient = &http.Client{Timeout: connectionTimeout} }