diff --git a/.gitignore b/.gitignore index dcb4cc633..cec47a064 100644 --- a/.gitignore +++ b/.gitignore @@ -16,8 +16,8 @@ # Common IDE paths .vscode/ +.idea/ vendor/**/ .env coverage.txt - diff --git a/account_invoices.go b/account_invoices.go index 6833ed257..d068662fa 100644 --- a/account_invoices.go +++ b/account_invoices.go @@ -18,7 +18,7 @@ type Invoice struct { Date *time.Time `json:"-"` } -// InvoiceItem structs reflect an single billable activity associate with an Invoice +// InvoiceItem structs reflect a single billable activity associate with an Invoice type InvoiceItem struct { Label string `json:"label"` Type string `json:"type"` @@ -105,7 +105,7 @@ func (i *InvoiceItem) UnmarshalJSON(b []byte) error { return nil } -// GetInvoice gets the a single Invoice matching the provided ID +// GetInvoice gets a single Invoice matching the provided ID func (c *Client) GetInvoice(ctx context.Context, invoiceID int) (*Invoice, error) { req := c.R(ctx).SetResult(&Invoice{}) e := fmt.Sprintf("account/invoices/%d", invoiceID) diff --git a/client.go b/client.go index 5262c8485..061a9320a 100644 --- a/client.go +++ b/client.go @@ -3,7 +3,6 @@ package linodego import ( "context" "fmt" - "io/ioutil" "log" "net/http" "net/url" @@ -166,7 +165,7 @@ func (c *Client) updateHostURL() { apiProto = c.apiProto } - c.resty.SetHostURL( + c.resty.SetBaseURL( fmt.Sprintf( "%s://%s/%s", apiProto, @@ -183,7 +182,7 @@ func (c *Client) SetRootCertificate(path string) *Client { } // SetToken sets the API token for all requests from this client -// Only necessary if you haven't already provided an http client to NewClient() configured with the token. +// Only necessary if you haven't already provided the http client to NewClient() configured with the token. func (c *Client) SetToken(token string) *Client { c.resty.SetHeader("Authorization", fmt.Sprintf("Bearer %s", token)) return c @@ -398,7 +397,7 @@ func NewClient(hc *http.Client) (client Client) { certPath, certPathExists := os.LookupEnv(APIHostCert) if certPathExists { - cert, err := ioutil.ReadFile(filepath.Clean(certPath)) + cert, err := os.ReadFile(filepath.Clean(certPath)) if err != nil { log.Fatalf("[ERROR] Error when reading cert at %s: %s\n", certPath, err.Error()) } diff --git a/client_test.go b/client_test.go index f969d9178..3e0c35906 100644 --- a/client_test.go +++ b/client_test.go @@ -24,39 +24,39 @@ func TestClient_SetAPIVersion(t *testing.T) { client := NewClient(nil) - if client.resty.HostURL != defaultURL { - t.Fatal(cmp.Diff(client.resty.HostURL, defaultURL)) + if client.resty.BaseURL != defaultURL { + t.Fatal(cmp.Diff(client.resty.BaseURL, defaultURL)) } client.SetBaseURL(baseURL) client.SetAPIVersion(apiVersion) - if client.resty.HostURL != expectedHost { - t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost)) + if client.resty.BaseURL != expectedHost { + t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost)) } // Ensure setting twice does not cause conflicts client.SetBaseURL(updatedBaseURL) client.SetAPIVersion(updatedAPIVersion) - if client.resty.HostURL != updatedExpectedHost { - t.Fatal(cmp.Diff(client.resty.HostURL, updatedExpectedHost)) + if client.resty.BaseURL != updatedExpectedHost { + t.Fatal(cmp.Diff(client.resty.BaseURL, updatedExpectedHost)) } // Revert client.SetBaseURL(baseURL) client.SetAPIVersion(apiVersion) - if client.resty.HostURL != expectedHost { - t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost)) + if client.resty.BaseURL != expectedHost { + t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost)) } // Custom protocol client.SetBaseURL(protocolBaseURL) client.SetAPIVersion(protocolAPIVersion) - if client.resty.HostURL != protocolExpectedHost { - t.Fatal(cmp.Diff(client.resty.HostURL, expectedHost)) + if client.resty.BaseURL != protocolExpectedHost { + t.Fatal(cmp.Diff(client.resty.BaseURL, expectedHost)) } } diff --git a/config.go b/config.go index 0d0b2f507..6bccf83f7 100644 --- a/config.go +++ b/config.go @@ -29,7 +29,7 @@ type LoadConfigOptions struct { SkipLoadProfile bool } -// LoadConfig loads a Linode config according to the options argument. +// LoadConfig loads a Linode config according to the option's argument. // If no options are specified, the following defaults will be used: // Path: ~/.config/linode // Profile: default diff --git a/config_test.go b/config_test.go index 2ec9d8d97..b4b3db418 100644 --- a/config_test.go +++ b/config_test.go @@ -2,7 +2,6 @@ package linodego import ( "fmt" - "io/ioutil" "os" "testing" ) @@ -43,8 +42,8 @@ func TestConfig_LoadWithDefaults(t *testing.T) { expectedURL := "https://api.cool.linode.com/v4beta" - if client.resty.HostURL != expectedURL { - t.Fatalf("mismatched host url: %s != %s", client.resty.HostURL, expectedURL) + if client.resty.BaseURL != expectedURL { + t.Fatalf("mismatched host url: %s != %s", client.resty.BaseURL, expectedURL) } if client.resty.Header.Get("Authorization") != "Bearer "+p.APIToken { @@ -89,8 +88,8 @@ func TestConfig_OverrideDefaults(t *testing.T) { expectedURL := "https://api.cool.linode.com/v4" - if client.resty.HostURL != expectedURL { - t.Fatalf("mismatched host url: %s != %s", client.resty.HostURL, expectedURL) + if client.resty.BaseURL != expectedURL { + t.Fatalf("mismatched host url: %s != %s", client.resty.BaseURL, expectedURL) } if client.resty.Header.Get("Authorization") != "Bearer "+p.APIToken { @@ -131,7 +130,7 @@ func TestConfig_NoDefaults(t *testing.T) { } func createTestConfig(t *testing.T, conf string) *os.File { - file, err := ioutil.TempFile("", "linode") + file, err := os.CreateTemp("", "linode") if err != nil { t.Fatal(err) } diff --git a/errors_test.go b/errors_test.go index 7206cdcb8..15510ec72 100644 --- a/errors_test.go +++ b/errors_test.go @@ -4,7 +4,7 @@ import ( "bytes" "context" "errors" - "io/ioutil" + "io" "net/http" "net/http/httptest" "testing" @@ -114,7 +114,7 @@ func TestCoupleAPIErrors_badGatewayError(t *testing.T) {