Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 29, 2023
1 parent dc824a8 commit 696c2eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
20 changes: 5 additions & 15 deletions providers/dns/beget/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion providers/dns/beget/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"testing"
Expand All @@ -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
}
Expand Down

0 comments on commit 696c2eb

Please sign in to comment.