From e2eda3283ea959b46ce15cb3f0d8301205dd3c9a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Wed, 29 Mar 2023 18:32:04 +0200 Subject: [PATCH] review --- providers/dns/beget/internal/client.go | 20 +++++--------------- providers/dns/beget/internal/client_test.go | 3 ++- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/providers/dns/beget/internal/client.go b/providers/dns/beget/internal/client.go index 3df4e13dd20..5519396306e 100644 --- a/providers/dns/beget/internal/client.go +++ b/providers/dns/beget/internal/client.go @@ -17,16 +17,18 @@ type Client struct { login string password string - baseURL string + baseURL *url.URL HTTPClient *http.Client } // NewClient Creates a beget.com client. func NewClient(login, password string) *Client { + baseURL, _ := url.Parse(defaultBaseURL) + return &Client{ login: login, password: password, - baseURL: defaultBaseURL, + baseURL: baseURL, HTTPClient: &http.Client{Timeout: 5 * time.Second}, } } @@ -68,10 +70,7 @@ func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain string) e } func (c Client) doRequest(ctx context.Context, data any, fragments ...string) (*APIResponse, error) { - endpoint, err := c.createEndpoint(fragments...) - if err != nil { - return nil, err - } + endpoint := c.baseURL.JoinPath(fragments...) inputData, err := json.Marshal(data) if err != nil { @@ -126,12 +125,3 @@ func (c Client) doRequest(ctx context.Context, data any, fragments ...string) (* return &apiResp, nil } - -func (c Client) createEndpoint(fragments ...string) (*url.URL, error) { - baseURL, err := url.Parse(c.baseURL) - if err != nil { - return nil, err - } - - return baseURL.JoinPath(fragments...), nil -} diff --git a/providers/dns/beget/internal/client_test.go b/providers/dns/beget/internal/client_test.go index 54396338403..c36d91043ba 100644 --- a/providers/dns/beget/internal/client_test.go +++ b/providers/dns/beget/internal/client_test.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "net/http/httptest" + "net/url" "os" "path/filepath" "testing" @@ -24,7 +25,7 @@ func setupTest(t *testing.T, handler http.HandlerFunc) *Client { client := NewClient("user", "secret") client.HTTPClient = server.Client() - client.baseURL = server.URL + client.baseURL, _ = url.Parse(server.URL) return client }