Skip to content

Commit 6569fa4

Browse files
committed
review
1 parent dc824a8 commit 6569fa4

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

providers/dns/beget/internal/client.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@ type Client struct {
1717
login string
1818
password string
1919

20-
baseURL string
20+
baseURL *url.URL
2121
HTTPClient *http.Client
2222
}
2323

2424
// NewClient Creates a beget.com client.
2525
func NewClient(login, password string) *Client {
26+
baseURL, _ := url.Parse(defaultBaseURL)
27+
2628
return &Client{
2729
login: login,
2830
password: password,
29-
baseURL: defaultBaseURL,
31+
baseURL: baseURL,
3032
HTTPClient: &http.Client{Timeout: 5 * time.Second},
3133
}
3234
}
@@ -68,10 +70,7 @@ func (c Client) RemoveTxtRecord(ctx context.Context, domain, subDomain string) e
6870
}
6971

7072
func (c Client) doRequest(ctx context.Context, data any, fragments ...string) (*APIResponse, error) {
71-
endpoint, err := c.createEndpoint(fragments...)
72-
if err != nil {
73-
return nil, err
74-
}
73+
endpoint := c.baseURL.JoinPath(fragments...)
7574

7675
inputData, err := json.Marshal(data)
7776
if err != nil {
@@ -127,11 +126,3 @@ func (c Client) doRequest(ctx context.Context, data any, fragments ...string) (*
127126
return &apiResp, nil
128127
}
129128

130-
func (c Client) createEndpoint(fragments ...string) (*url.URL, error) {
131-
baseURL, err := url.Parse(c.baseURL)
132-
if err != nil {
133-
return nil, err
134-
}
135-
136-
return baseURL.JoinPath(fragments...), nil
137-
}

providers/dns/beget/internal/client_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net/http"
88
"net/http/httptest"
9+
"net/url"
910
"os"
1011
"path/filepath"
1112
"testing"
@@ -24,7 +25,7 @@ func setupTest(t *testing.T, handler http.HandlerFunc) *Client {
2425

2526
client := NewClient("user", "secret")
2627
client.HTTPClient = server.Client()
27-
client.baseURL = server.URL
28+
client.baseURL, _ = url.Parse(server.URL)
2829

2930
return client
3031
}

0 commit comments

Comments
 (0)