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) {
nginx
`) - buf := ioutil.NopCloser(bytes.NewBuffer(rawResponse)) + buf := io.NopCloser(bytes.NewBuffer(rawResponse)) resp := &resty.Response{ Request: &resty.Request{ diff --git a/go.mod b/go.mod index 67a6ca30b..a1a597f03 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,11 @@ require ( github.com/go-resty/resty/v2 v2.7.0 github.com/google/go-cmp v0.5.7 golang.org/x/net v0.15.0 + golang.org/x/text v0.13.0 gopkg.in/ini.v1 v1.66.6 ) -require ( - github.com/stretchr/testify v1.8.4 // indirect - golang.org/x/text v0.13.0 // indirect -) +require github.com/stretchr/testify v1.8.4 // indirect go 1.20 diff --git a/images.go b/images.go index d9e29f49e..7875d6fdc 100644 --- a/images.go +++ b/images.go @@ -148,7 +148,7 @@ func (c *Client) GetImage(ctx context.Context, imageID string) (*Image, error) { return r.Result().(*Image), nil } -// CreateImage creates a Image +// CreateImage creates an Image func (c *Client) CreateImage(ctx context.Context, opts ImageCreateOptions) (*Image, error) { body, err := json.Marshal(opts) if err != nil { diff --git a/mysql.go b/mysql.go index 52161bb65..575d0b27b 100644 --- a/mysql.go +++ b/mysql.go @@ -19,7 +19,7 @@ const ( MySQLDatabaseTargetSecondary MySQLDatabaseTarget = "secondary" ) -// A MySQLDatabase is a instance of Linode MySQL Managed Databases +// A MySQLDatabase is an instance of Linode MySQL Managed Databases type MySQLDatabase struct { ID int `json:"id"` Status DatabaseStatus `json:"status"` diff --git a/postgres.go b/postgres.go index 2484ecdf9..35158b6e5 100644 --- a/postgres.go +++ b/postgres.go @@ -35,7 +35,7 @@ const ( PostgresReplicationSemiSynch PostgresReplicationType = "semi_synch" ) -// A PostgresDatabase is a instance of Linode Postgres Managed Databases +// A PostgresDatabase is an instance of Linode Postgres Managed Databases type PostgresDatabase struct { ID int `json:"id"` Status DatabaseStatus `json:"status"` diff --git a/test/integration/longview_test.go b/test/integration/longview_test.go index 1e0ba0179..da0a29339 100644 --- a/test/integration/longview_test.go +++ b/test/integration/longview_test.go @@ -99,7 +99,7 @@ func TestLongviewClient_Delete(t *testing.T) { t.Errorf("Error getting longview client:%s", getErr) } - // If there is no error, the longview client was delete properly + // If there is no error, the longview client was deleted properly if err := client.DeleteLongviewClient(context.Background(), testingLongviewClient.ID); err != nil { t.Fatal(err) } diff --git a/test/integration/util_test.go b/test/integration/util_test.go index a3ad1cb41..f73ca223e 100644 --- a/test/integration/util_test.go +++ b/test/integration/util_test.go @@ -3,7 +3,7 @@ package integration import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "reflect" "regexp" @@ -29,7 +29,7 @@ func mockRequestBodyValidate(t *testing.T, expected interface{}, response interf i := result.Interface() - data, err := ioutil.ReadAll(request.Body) + data, err := io.ReadAll(request.Body) if err != nil { t.Fatal(err) } diff --git a/waitfor.go b/waitfor.go index 649554b4f..e31426948 100644 --- a/waitfor.go +++ b/waitfor.go @@ -6,10 +6,14 @@ import ( "log" "net/http" "strconv" - "strings" "time" + + "golang.org/x/text/cases" + "golang.org/x/text/language" ) +var englishTitle = cases.Title(language.English) + type EventPoller struct { EntityID any EntityType EntityType @@ -284,7 +288,7 @@ func (client Client) WaitForEventFinished( minStart time.Time, timeoutSeconds int, ) (*Event, error) { - titledEntityType := strings.Title(string(entityType)) + titledEntityType := englishTitle.String(string(entityType)) filter := Filter{ Order: Descending, OrderBy: "created",