From d679d8f2d2601e95035e4f0eb10a35ab0aea9aae Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Mon, 24 Jul 2023 15:14:24 -0400 Subject: [PATCH] Implement stricter golangci-lint configurations (#259) * Fix whitespace and false positivies on duplicates * Fix no context on http request * Ignore long lines on function definitions * Add golangci yaml configuration file * Resolve gocritic issues * Constantify the instance response * Ignore false positives on duplicates --- .golangci.yaml | 135 +++++++++++++++++++++++++++ account_test.go | 3 +- application.go | 2 +- application_test.go | 1 - backup.go | 2 +- backup_test.go | 5 +- bare_metal_server.go | 10 +- bare_metal_server_test.go | 1 - billing.go | 6 +- billing_test.go | 6 -- block_storage.go | 2 +- database.go | 55 +++++------ domain_records.go | 4 +- domains.go | 3 +- firewall_group.go | 4 +- firewall_rule.go | 4 +- govultr.go | 2 +- govultr_test.go | 20 ++-- instance.go | 16 ++-- instance_test.go | 186 +++++++++----------------------------- iso.go | 4 +- kubernetes.go | 21 +++-- kubernetes_test.go | 6 +- load_balancer.go | 56 ++++++------ load_balancer_test.go | 1 - network.go | 6 +- object_storage.go | 10 +- os.go | 2 +- plans.go | 2 +- regions.go | 2 +- reserved_ip.go | 4 +- snapshot.go | 2 +- ssh_key.go | 4 +- startup_script.go | 4 +- user.go | 4 +- vpc.go | 6 +- 36 files changed, 309 insertions(+), 292 deletions(-) create mode 100644 .golangci.yaml diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..682abf3 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,135 @@ +linters-settings: + dupl: + threshold: 100 + funlen: + lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner. + statements: 50 + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + gocyclo: + min-complexity: 15 + goimports: + local-prefixes: github.com/golangci/golangci-lint + gomnd: + # don't include the "operation" and "assign" + checks: + - argument + - case + - condition + - return + ignored-numbers: + - '0' + - '1' + - '2' + - '3' + ignored-functions: + - strings.SplitN + + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 140 + misspell: + locale: US + nolintlint: + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + revive: + rules: + - name: unexported-return + disabled: true + +linters: + disable-all: true + enable: + - dogsled + - dupl + - errcheck + - exportloopref + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - gomnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - revive + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + + # don't enable: + # - bodyclose + # - depguard + # - asciicheck + # - scopelint + # - gochecknoglobals + # - gocognit + # - godot + # - godox + # - goerr113 + # - interfacer + # - maligned + # - nestif + # - prealloc + # - testpackage + # - wsl + +issues: + # List of regexps of issue texts to exclude. + # + # But independently of this option we use default exclude patterns, + # it can be disabled by `exclude-use-default: false`. + # To list all excluded by default patterns execute `golangci-lint run --help` + # + # Default: https://golangci-lint.run/usage/false-positives/#default-exclusions + exclude: + - abcdef + exclude-rules: + # Exclude some linters from running on tests files. + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - lll + +run: + timeout: 5m diff --git a/account_test.go b/account_test.go index 4e270b9..af95377 100644 --- a/account_test.go +++ b/account_test.go @@ -12,9 +12,8 @@ func TestAccountServiceHandler_Get(t *testing.T) { defer teardown() mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) { - response := ` - { + { "account" : { "balance": -5519.11, "pending_charges": 57.03, diff --git a/application.go b/application.go index c8b7732..319a827 100644 --- a/application.go +++ b/application.go @@ -35,7 +35,7 @@ type applicationBase struct { } // List retrieves a list of available applications that can be launched when creating a Vultr instance -func (a *ApplicationServiceHandler) List(ctx context.Context, options *ListOptions) ([]Application, *Meta, *http.Response, error) { +func (a *ApplicationServiceHandler) List(ctx context.Context, options *ListOptions) ([]Application, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/applications" req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/application_test.go b/application_test.go index 9ea4a39..9aef979 100644 --- a/application_test.go +++ b/application_test.go @@ -12,7 +12,6 @@ func TestApplicationServiceHandler_List(t *testing.T) { defer teardown() mux.HandleFunc("/v2/applications", func(w http.ResponseWriter, r *http.Request) { - response := ` { "applications": [ diff --git a/backup.go b/backup.go index 350d3f8..24c6f9a 100644 --- a/backup.go +++ b/backup.go @@ -57,7 +57,7 @@ func (b *BackupServiceHandler) Get(ctx context.Context, backupID string) (*Backu } // List retrieves a list of all backups on the current account -func (b *BackupServiceHandler) List(ctx context.Context, options *ListOptions) ([]Backup, *Meta, *http.Response, error) { +func (b *BackupServiceHandler) List(ctx context.Context, options *ListOptions) ([]Backup, *Meta, *http.Response, error) { //nolint:dupl uri := "/v2/backups" req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/backup_test.go b/backup_test.go index 1669d51..925a3b5 100644 --- a/backup_test.go +++ b/backup_test.go @@ -12,7 +12,6 @@ func TestBackupServiceHandler_List(t *testing.T) { defer teardown() mux.HandleFunc("/v2/backups", func(w http.ResponseWriter, r *http.Request) { - response := ` { "backups": [ @@ -71,7 +70,6 @@ func TestBackupServiceHandler_ListEmpty(t *testing.T) { defer teardown() mux.HandleFunc("/v2/backups", func(w http.ResponseWriter, r *http.Request) { - response := ` { "backups": [], @@ -117,7 +115,6 @@ func TestBackupServiceHandler_Get(t *testing.T) { defer teardown() mux.HandleFunc("/v2/backups/543d34149403a", func(w http.ResponseWriter, r *http.Request) { - response := ` { "backup": { @@ -156,7 +153,7 @@ func TestBackupServiceHandler_GetEmpty(t *testing.T) { defer teardown() mux.HandleFunc("/v2/backups/543d34149403a", func(w http.ResponseWriter, r *http.Request) { - response := ` + response := ` { "backup": {} } diff --git a/bare_metal_server.go b/bare_metal_server.go index 72e34b8..ea847c8 100644 --- a/bare_metal_server.go +++ b/bare_metal_server.go @@ -122,7 +122,7 @@ type bareMetalBase struct { BareMetal *BareMetalServer `json:"bare_metal"` } -// BMBareMetalBase ... +// BMBareMetalBase represents the base struct for a Bare Metal server type BMBareMetalBase struct { BareMetalBandwidth map[string]BareMetalServerBandwidth `json:"bandwidth"` } @@ -170,7 +170,7 @@ func (b *BareMetalServerServiceHandler) Get(ctx context.Context, serverID string } // Update a Bare Metal server -func (b *BareMetalServerServiceHandler) Update(ctx context.Context, serverID string, bmReq *BareMetalUpdate) (*BareMetalServer, *http.Response, error) { +func (b *BareMetalServerServiceHandler) Update(ctx context.Context, serverID string, bmReq *BareMetalUpdate) (*BareMetalServer, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s", bmPath, serverID) req, err := b.client.NewRequest(ctx, http.MethodPatch, uri, bmReq) if err != nil { @@ -198,7 +198,7 @@ func (b *BareMetalServerServiceHandler) Delete(ctx context.Context, serverID str } // List all Bare Metal instances in your account. -func (b *BareMetalServerServiceHandler) List(ctx context.Context, options *ListOptions) ([]BareMetalServer, *Meta, *http.Response, error) { +func (b *BareMetalServerServiceHandler) List(ctx context.Context, options *ListOptions) ([]BareMetalServer, *Meta, *http.Response, error) { //nolint:dupl,lll req, err := b.client.NewRequest(ctx, http.MethodGet, bmPath, nil) if err != nil { return nil, nil, nil, err @@ -273,7 +273,7 @@ func (b *BareMetalServerServiceHandler) GetVNCUrl(ctx context.Context, serverID // ListIPv4s information of a Bare Metal server. // IP information is only available for Bare Metal servers in the "active" state. -func (b *BareMetalServerServiceHandler) ListIPv4s(ctx context.Context, serverID string, options *ListOptions) ([]IPv4, *Meta, *http.Response, error) { +func (b *BareMetalServerServiceHandler) ListIPv4s(ctx context.Context, serverID string, options *ListOptions) ([]IPv4, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/ipv4", bmPath, serverID) req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -299,7 +299,7 @@ func (b *BareMetalServerServiceHandler) ListIPv4s(ctx context.Context, serverID // ListIPv6s information of a Bare Metal server. // IP information is only available for Bare Metal servers in the "active" state. // If the Bare Metal server does not have IPv6 enabled, then an empty array is returned. -func (b *BareMetalServerServiceHandler) ListIPv6s(ctx context.Context, serverID string, options *ListOptions) ([]IPv6, *Meta, *http.Response, error) { +func (b *BareMetalServerServiceHandler) ListIPv6s(ctx context.Context, serverID string, options *ListOptions) ([]IPv6, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/ipv6", bmPath, serverID) req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { diff --git a/bare_metal_server_test.go b/bare_metal_server_test.go index d097a8d..4afbb6a 100644 --- a/bare_metal_server_test.go +++ b/bare_metal_server_test.go @@ -642,7 +642,6 @@ func TestBareMetalServerServiceHandler_GetUpgrades(t *testing.T) { if !reflect.DeepEqual(server, expected) { t.Errorf("BareMetalServer.GetUpgrades returned %+v, expected %+v", server, expected) - } } func TestBareMetalServerServiceHandler_GetVNCUrl(t *testing.T) { diff --git a/billing.go b/billing.go index 03bf6c4..f1dd15c 100644 --- a/billing.go +++ b/billing.go @@ -73,7 +73,7 @@ type invoiceItemsBase struct { } // ListHistory retrieves a list of all billing history on the current account -func (b *BillingServiceHandler) ListHistory(ctx context.Context, options *ListOptions) ([]History, *Meta, *http.Response, error) { +func (b *BillingServiceHandler) ListHistory(ctx context.Context, options *ListOptions) ([]History, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/billing/history" req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -97,7 +97,7 @@ func (b *BillingServiceHandler) ListHistory(ctx context.Context, options *ListOp } // ListInvoices retrieves a list of all billing invoices on the current account -func (b *BillingServiceHandler) ListInvoices(ctx context.Context, options *ListOptions) ([]Invoice, *Meta, *http.Response, error) { +func (b *BillingServiceHandler) ListInvoices(ctx context.Context, options *ListOptions) ([]Invoice, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/billing/invoices" req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -139,7 +139,7 @@ func (b *BillingServiceHandler) GetInvoice(ctx context.Context, invoiceID string } // ListInvoiceItems retrieves items in an invoice that matches the given invoiceID -func (b *BillingServiceHandler) ListInvoiceItems(ctx context.Context, invoiceID int, options *ListOptions) ([]InvoiceItem, *Meta, *http.Response, error) { +func (b *BillingServiceHandler) ListInvoiceItems(ctx context.Context, invoiceID int, options *ListOptions) ([]InvoiceItem, *Meta, *http.Response, error) { //nolint:dupl,lll uri := fmt.Sprintf("/v2/billing/invoices/%d/items", invoiceID) req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { diff --git a/billing_test.go b/billing_test.go index eb5d46d..2ac09c7 100644 --- a/billing_test.go +++ b/billing_test.go @@ -12,7 +12,6 @@ func TestBillingServiceHandler_ListHistory(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/history", func(w http.ResponseWriter, r *http.Request) { - response := ` { "billing_history": [ @@ -73,7 +72,6 @@ func TestBillingServiceHandler_ListInvoices(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/invoices", func(w http.ResponseWriter, r *http.Request) { - response := ` { "billing_invoices": [ @@ -132,7 +130,6 @@ func TestBillingServiceHandler_ListHistoryEmpty(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/history", func(w http.ResponseWriter, r *http.Request) { - response := ` { "billing_history": [], @@ -178,7 +175,6 @@ func TestBillingServiceHandler_ListInvoicesEmpty(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/invoices", func(w http.ResponseWriter, r *http.Request) { - response := ` { "billing_invoices": [], @@ -224,7 +220,6 @@ func TestBillingServiceHandler_GetInvoice(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/invoices/123456", func(w http.ResponseWriter, r *http.Request) { - response := ` { "billing_invoice": { @@ -263,7 +258,6 @@ func TestBillingServiceHandler_ListInvoiceItems(t *testing.T) { defer teardown() mux.HandleFunc("/v2/billing/invoices/123456/items", func(w http.ResponseWriter, r *http.Request) { - response := ` { "invoice_items": [ diff --git a/block_storage.go b/block_storage.go index 50d8baf..702dc1b 100644 --- a/block_storage.go +++ b/block_storage.go @@ -135,7 +135,7 @@ func (b *BlockStorageServiceHandler) Delete(ctx context.Context, blockID string) } // List returns a list of all block storage instances on your Vultr Account -func (b *BlockStorageServiceHandler) List(ctx context.Context, options *ListOptions) ([]BlockStorage, *Meta, *http.Response, error) { +func (b *BlockStorageServiceHandler) List(ctx context.Context, options *ListOptions) ([]BlockStorage, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/blocks" req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/database.go b/database.go index 0775601..be9fb57 100644 --- a/database.go +++ b/database.go @@ -24,7 +24,7 @@ type DatabaseService interface { ListUsers(ctx context.Context, databaseID string) ([]DatabaseUser, *Meta, *http.Response, error) CreateUser(ctx context.Context, databaseID string, databaseUserReq *DatabaseUserCreateReq) (*DatabaseUser, *http.Response, error) GetUser(ctx context.Context, databaseID string, username string) (*DatabaseUser, *http.Response, error) - UpdateUser(ctx context.Context, databaseID string, username string, databaseUserReq *DatabaseUserUpdateReq) (*DatabaseUser, *http.Response, error) + UpdateUser(ctx context.Context, databaseID string, username string, databaseUserReq *DatabaseUserUpdateReq) (*DatabaseUser, *http.Response, error) //nolint:lll DeleteUser(ctx context.Context, databaseID string, username string) error ListDBs(ctx context.Context, databaseID string) ([]DatabaseDB, *Meta, *http.Response, error) @@ -35,10 +35,10 @@ type DatabaseService interface { ListMaintenanceUpdates(ctx context.Context, databaseID string) ([]string, *http.Response, error) StartMaintenance(ctx context.Context, databaseID string) (string, *http.Response, error) - ListServiceAlerts(ctx context.Context, databaseID string, databaseAlertsReq *DatabaseListAlertsReq) ([]DatabaseAlert, *http.Response, error) + ListServiceAlerts(ctx context.Context, databaseID string, databaseAlertsReq *DatabaseListAlertsReq) ([]DatabaseAlert, *http.Response, error) //nolint:lll GetMigrationStatus(ctx context.Context, databaseID string) (*DatabaseMigration, *http.Response, error) - StartMigration(ctx context.Context, databaseID string, databaseMigrationReq *DatabaseMigrationStartReq) (*DatabaseMigration, *http.Response, error) + StartMigration(ctx context.Context, databaseID string, databaseMigrationReq *DatabaseMigrationStartReq) (*DatabaseMigration, *http.Response, error) //nolint:lll DetachMigration(ctx context.Context, databaseID string) error AddReadOnlyReplica(ctx context.Context, databaseID string, databaseReplicaReq *DatabaseAddReplicaReq) (*Database, *http.Response, error) @@ -48,16 +48,16 @@ type DatabaseService interface { Fork(ctx context.Context, databaseID string, databaseForkReq *DatabaseForkReq) (*Database, *http.Response, error) ListConnectionPools(ctx context.Context, databaseID string) (*DatabaseConnections, []DatabaseConnectionPool, *Meta, *http.Response, error) - CreateConnectionPool(ctx context.Context, databaseID string, databaseConnectionPoolReq *DatabaseConnectionPoolCreateReq) (*DatabaseConnectionPool, *http.Response, error) + CreateConnectionPool(ctx context.Context, databaseID string, databaseConnectionPoolReq *DatabaseConnectionPoolCreateReq) (*DatabaseConnectionPool, *http.Response, error) //nolint:lll GetConnectionPool(ctx context.Context, databaseID string, poolName string) (*DatabaseConnectionPool, *http.Response, error) - UpdateConnectionPool(ctx context.Context, databaseID string, poolName string, databaseConnectionPoolReq *DatabaseConnectionPoolUpdateReq) (*DatabaseConnectionPool, *http.Response, error) + UpdateConnectionPool(ctx context.Context, databaseID string, poolName string, databaseConnectionPoolReq *DatabaseConnectionPoolUpdateReq) (*DatabaseConnectionPool, *http.Response, error) //nolint:lll DeleteConnectionPool(ctx context.Context, databaseID string, poolName string) error ListAdvancedOptions(ctx context.Context, databaseID string) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) - UpdateAdvancedOptions(ctx context.Context, databaseID string, databaseAdvancedOptionsReq *DatabaseAdvancedOptions) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) + UpdateAdvancedOptions(ctx context.Context, databaseID string, databaseAdvancedOptionsReq *DatabaseAdvancedOptions) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) //nolint:lll ListAvailableVersions(ctx context.Context, databaseID string) ([]string, *http.Response, error) - StartVersionUpgrade(ctx context.Context, databaseID string, databaseVersionUpgradeReq *DatabaseVersionUpgradeReq) (string, *http.Response, error) + StartVersionUpgrade(ctx context.Context, databaseID string, databaseVersionUpgradeReq *DatabaseVersionUpgradeReq) (string, *http.Response, error) //nolint:lll } // DatabaseServiceHandler handles interaction with the server methods for the Vultr API @@ -500,7 +500,7 @@ func (d *DatabaseServiceHandler) ListPlans(ctx context.Context, options *DBPlanL } // List retrieves all databases on your account -func (d *DatabaseServiceHandler) List(ctx context.Context, options *DBListOptions) ([]Database, *Meta, *http.Response, error) { +func (d *DatabaseServiceHandler) List(ctx context.Context, options *DBListOptions) ([]Database, *Meta, *http.Response, error) { //nolint:dupl,lll req, err := d.client.NewRequest(ctx, http.MethodGet, databasePath, nil) if err != nil { return nil, nil, nil, err @@ -557,7 +557,7 @@ func (d *DatabaseServiceHandler) Get(ctx context.Context, databaseID string) (*D } // Update will update the Managed Database with the given parameters -func (d *DatabaseServiceHandler) Update(ctx context.Context, databaseID string, databaseReq *DatabaseUpdateReq) (*Database, *http.Response, error) { +func (d *DatabaseServiceHandler) Update(ctx context.Context, databaseID string, databaseReq *DatabaseUpdateReq) (*Database, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPut, uri, databaseReq) @@ -588,7 +588,7 @@ func (d *DatabaseServiceHandler) Delete(ctx context.Context, databaseID string) } // ListUsers retrieves all database users on your Managed Database. -func (d *DatabaseServiceHandler) ListUsers(ctx context.Context, databaseID string) ([]DatabaseUser, *Meta, *http.Response, error) { +func (d *DatabaseServiceHandler) ListUsers(ctx context.Context, databaseID string) ([]DatabaseUser, *Meta, *http.Response, error) { //nolint:dupl,lll uri := fmt.Sprintf("%s/%s/users", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -606,7 +606,7 @@ func (d *DatabaseServiceHandler) ListUsers(ctx context.Context, databaseID strin } // CreateUser will create a user within the Managed Database with the given parameters -func (d *DatabaseServiceHandler) CreateUser(ctx context.Context, databaseID string, databaseUserReq *DatabaseUserCreateReq) (*DatabaseUser, *http.Response, error) { +func (d *DatabaseServiceHandler) CreateUser(ctx context.Context, databaseID string, databaseUserReq *DatabaseUserCreateReq) (*DatabaseUser, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/users", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseUserReq) @@ -642,7 +642,7 @@ func (d *DatabaseServiceHandler) GetUser(ctx context.Context, databaseID, userna } // UpdateUser will update a user within the Managed Database with the given parameters -func (d *DatabaseServiceHandler) UpdateUser(ctx context.Context, databaseID, username string, databaseUserReq *DatabaseUserUpdateReq) (*DatabaseUser, *http.Response, error) { +func (d *DatabaseServiceHandler) UpdateUser(ctx context.Context, databaseID, username string, databaseUserReq *DatabaseUserUpdateReq) (*DatabaseUser, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/users/%s", databasePath, databaseID, username) req, err := d.client.NewRequest(ctx, http.MethodPut, uri, databaseUserReq) @@ -673,7 +673,7 @@ func (d *DatabaseServiceHandler) DeleteUser(ctx context.Context, databaseID, use } // ListDBs retrieves all logical databases on your Managed Database. -func (d *DatabaseServiceHandler) ListDBs(ctx context.Context, databaseID string) ([]DatabaseDB, *Meta, *http.Response, error) { +func (d *DatabaseServiceHandler) ListDBs(ctx context.Context, databaseID string) ([]DatabaseDB, *Meta, *http.Response, error) { //nolint:dupl,lll uri := fmt.Sprintf("%s/%s/dbs", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -691,7 +691,7 @@ func (d *DatabaseServiceHandler) ListDBs(ctx context.Context, databaseID string) } // CreateDB will create a logical database within the Managed Database with the given parameters -func (d *DatabaseServiceHandler) CreateDB(ctx context.Context, databaseID string, databaseDBReq *DatabaseDBCreateReq) (*DatabaseDB, *http.Response, error) { +func (d *DatabaseServiceHandler) CreateDB(ctx context.Context, databaseID string, databaseDBReq *DatabaseDBCreateReq) (*DatabaseDB, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/dbs", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseDBReq) @@ -776,7 +776,7 @@ func (d *DatabaseServiceHandler) StartMaintenance(ctx context.Context, databaseI } // ListServiceAlerts queries for service alerts for the Managed Database using the given parameters -func (d *DatabaseServiceHandler) ListServiceAlerts(ctx context.Context, databaseID string, databaseAlertsReq *DatabaseListAlertsReq) ([]DatabaseAlert, *http.Response, error) { +func (d *DatabaseServiceHandler) ListServiceAlerts(ctx context.Context, databaseID string, databaseAlertsReq *DatabaseListAlertsReq) ([]DatabaseAlert, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/alerts", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseAlertsReq) @@ -812,7 +812,7 @@ func (d *DatabaseServiceHandler) GetMigrationStatus(ctx context.Context, databas } // StartMigration will start a migration for the Managed Database using the given credentials. -func (d *DatabaseServiceHandler) StartMigration(ctx context.Context, databaseID string, databaseMigrationReq *DatabaseMigrationStartReq) (*DatabaseMigration, *http.Response, error) { +func (d *DatabaseServiceHandler) StartMigration(ctx context.Context, databaseID string, databaseMigrationReq *DatabaseMigrationStartReq) (*DatabaseMigration, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/migration", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseMigrationReq) @@ -843,7 +843,7 @@ func (d *DatabaseServiceHandler) DetachMigration(ctx context.Context, databaseID } // AddReadOnlyReplica will add a read-only replica node to the Managed Database with the given parameters -func (d *DatabaseServiceHandler) AddReadOnlyReplica(ctx context.Context, databaseID string, databaseReplicaReq *DatabaseAddReplicaReq) (*Database, *http.Response, error) { +func (d *DatabaseServiceHandler) AddReadOnlyReplica(ctx context.Context, databaseID string, databaseReplicaReq *DatabaseAddReplicaReq) (*Database, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/read-replica", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseReplicaReq) @@ -879,7 +879,7 @@ func (d *DatabaseServiceHandler) GetBackupInformation(ctx context.Context, datab } // RestoreFromBackup will create a new subscription of the same plan from a backup of the Managed Database using the given parameters -func (d *DatabaseServiceHandler) RestoreFromBackup(ctx context.Context, databaseID string, databaseRestoreReq *DatabaseBackupRestoreReq) (*Database, *http.Response, error) { +func (d *DatabaseServiceHandler) RestoreFromBackup(ctx context.Context, databaseID string, databaseRestoreReq *DatabaseBackupRestoreReq) (*Database, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/restore", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseRestoreReq) @@ -897,7 +897,7 @@ func (d *DatabaseServiceHandler) RestoreFromBackup(ctx context.Context, database } // Fork will create a new subscription of any plan from a backup of the Managed Database using the given parameters -func (d *DatabaseServiceHandler) Fork(ctx context.Context, databaseID string, databaseForkReq *DatabaseForkReq) (*Database, *http.Response, error) { +func (d *DatabaseServiceHandler) Fork(ctx context.Context, databaseID string, databaseForkReq *DatabaseForkReq) (*Database, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/fork", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseForkReq) @@ -915,7 +915,7 @@ func (d *DatabaseServiceHandler) Fork(ctx context.Context, databaseID string, da } // ListConnectionPools retrieves all connection pools within your PostgreSQL Managed Database. -func (d *DatabaseServiceHandler) ListConnectionPools(ctx context.Context, databaseID string) (*DatabaseConnections, []DatabaseConnectionPool, *Meta, *http.Response, error) { +func (d *DatabaseServiceHandler) ListConnectionPools(ctx context.Context, databaseID string) (*DatabaseConnections, []DatabaseConnectionPool, *Meta, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/connection-pools", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -933,7 +933,7 @@ func (d *DatabaseServiceHandler) ListConnectionPools(ctx context.Context, databa } // CreateConnectionPool will create a connection pool within the PostgreSQL Managed Database with the given parameters -func (d *DatabaseServiceHandler) CreateConnectionPool(ctx context.Context, databaseID string, databaseConnectionPoolReq *DatabaseConnectionPoolCreateReq) (*DatabaseConnectionPool, *http.Response, error) { +func (d *DatabaseServiceHandler) CreateConnectionPool(ctx context.Context, databaseID string, databaseConnectionPoolReq *DatabaseConnectionPoolCreateReq) (*DatabaseConnectionPool, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/connection-pools", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseConnectionPoolReq) @@ -950,8 +950,9 @@ func (d *DatabaseServiceHandler) CreateConnectionPool(ctx context.Context, datab return databaseConnectionPool.ConnectionPool, resp, nil } -// GetConnectionPool retrieves information on an individual connection pool within a PostgreSQL Managed Database based on a poolName and databaseID -func (d *DatabaseServiceHandler) GetConnectionPool(ctx context.Context, databaseID, poolName string) (*DatabaseConnectionPool, *http.Response, error) { +// GetConnectionPool retrieves information on an individual connection pool +// within a PostgreSQL Managed Database based on a poolName and databaseID +func (d *DatabaseServiceHandler) GetConnectionPool(ctx context.Context, databaseID, poolName string) (*DatabaseConnectionPool, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/connection-pools/%s", databasePath, databaseID, poolName) req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -969,7 +970,7 @@ func (d *DatabaseServiceHandler) GetConnectionPool(ctx context.Context, database } // UpdateConnectionPool will update a connection pool within the PostgreSQL Managed Database with the given parameters -func (d *DatabaseServiceHandler) UpdateConnectionPool(ctx context.Context, databaseID, poolName string, databaseConnectionPoolReq *DatabaseConnectionPoolUpdateReq) (*DatabaseConnectionPool, *http.Response, error) { +func (d *DatabaseServiceHandler) UpdateConnectionPool(ctx context.Context, databaseID, poolName string, databaseConnectionPoolReq *DatabaseConnectionPoolUpdateReq) (*DatabaseConnectionPool, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/connection-pools/%s", databasePath, databaseID, poolName) req, err := d.client.NewRequest(ctx, http.MethodPut, uri, databaseConnectionPoolReq) @@ -1000,7 +1001,7 @@ func (d *DatabaseServiceHandler) DeleteConnectionPool(ctx context.Context, datab } // ListAdvancedOptions retrieves all connection pools within your PostgreSQL Managed Database. -func (d *DatabaseServiceHandler) ListAdvancedOptions(ctx context.Context, databaseID string) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) { +func (d *DatabaseServiceHandler) ListAdvancedOptions(ctx context.Context, databaseID string) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/advanced-options", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -1018,7 +1019,7 @@ func (d *DatabaseServiceHandler) ListAdvancedOptions(ctx context.Context, databa } // UpdateAdvancedOptions will update a connection pool within the PostgreSQL Managed Database with the given parameters -func (d *DatabaseServiceHandler) UpdateAdvancedOptions(ctx context.Context, databaseID string, databaseAdvancedOptionsReq *DatabaseAdvancedOptions) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) { +func (d *DatabaseServiceHandler) UpdateAdvancedOptions(ctx context.Context, databaseID string, databaseAdvancedOptionsReq *DatabaseAdvancedOptions) (*DatabaseAdvancedOptions, []AvailableOption, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/advanced-options", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPut, uri, databaseAdvancedOptionsReq) @@ -1054,7 +1055,7 @@ func (d *DatabaseServiceHandler) ListAvailableVersions(ctx context.Context, data } // StartVersionUpgrade will start a migration for the Managed Database using the given credentials. -func (d *DatabaseServiceHandler) StartVersionUpgrade(ctx context.Context, databaseID string, databaseVersionUpgradeReq *DatabaseVersionUpgradeReq) (string, *http.Response, error) { +func (d *DatabaseServiceHandler) StartVersionUpgrade(ctx context.Context, databaseID string, databaseVersionUpgradeReq *DatabaseVersionUpgradeReq) (string, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/version-upgrade", databasePath, databaseID) req, err := d.client.NewRequest(ctx, http.MethodPost, uri, databaseVersionUpgradeReq) diff --git a/domain_records.go b/domain_records.go index 2bce1f4..7e1fa2b 100644 --- a/domain_records.go +++ b/domain_records.go @@ -52,7 +52,7 @@ type domainRecordBase struct { } // Create will add a DNS record. -func (d *DomainRecordsServiceHandler) Create(ctx context.Context, domain string, domainRecordReq *DomainRecordReq) (*DomainRecord, *http.Response, error) { +func (d *DomainRecordsServiceHandler) Create(ctx context.Context, domain string, domainRecordReq *DomainRecordReq) (*DomainRecord, *http.Response, error) { //nolint:lll req, err := d.client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s/%s/records", domainPath, domain), domainRecordReq) if err != nil { return nil, nil, err @@ -105,7 +105,7 @@ func (d *DomainRecordsServiceHandler) Delete(ctx context.Context, domain, record } // List will list all the records associated with a particular domain on Vultr. -func (d *DomainRecordsServiceHandler) List(ctx context.Context, domain string, options *ListOptions) ([]DomainRecord, *Meta, *http.Response, error) { +func (d *DomainRecordsServiceHandler) List(ctx context.Context, domain string, options *ListOptions) ([]DomainRecord, *Meta, *http.Response, error) { //nolint:lll req, err := d.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/records", domainPath, domain), nil) if err != nil { return nil, nil, nil, err diff --git a/domains.go b/domains.go index b0db188..36ec35e 100644 --- a/domains.go +++ b/domains.go @@ -124,7 +124,7 @@ func (d *DomainServiceHandler) Delete(ctx context.Context, domain string) error } // List gets all domains associated with the current Vultr account. -func (d *DomainServiceHandler) List(ctx context.Context, options *ListOptions) ([]Domain, *Meta, *http.Response, error) { +func (d *DomainServiceHandler) List(ctx context.Context, options *ListOptions) ([]Domain, *Meta, *http.Response, error) { //nolint:dupl req, err := d.client.NewRequest(ctx, http.MethodGet, domainPath, nil) if err != nil { return nil, nil, nil, err @@ -164,7 +164,6 @@ func (d *DomainServiceHandler) GetSoa(ctx context.Context, domain string) (*Soa, // UpdateSoa will update the SOA record information for a domain. func (d *DomainServiceHandler) UpdateSoa(ctx context.Context, domain string, soaReq *Soa) error { - req, err := d.client.NewRequest(ctx, http.MethodPatch, fmt.Sprintf("%s/%s/soa", domainPath, domain), soaReq) if err != nil { return err diff --git a/firewall_group.go b/firewall_group.go index 2dcda10..4a77171 100644 --- a/firewall_group.go +++ b/firewall_group.go @@ -10,7 +10,7 @@ import ( // FirewallGroupService is the interface to interact with the firewall group endpoints on the Vultr API // Link : https://www.vultr.com/api/#tag/firewall -type FirewallGroupService interface { +type FirewallGroupService interface { //nolint:dupl Create(ctx context.Context, fwGroupReq *FirewallGroupReq) (*FirewallGroup, *http.Response, error) Get(ctx context.Context, groupID string) (*FirewallGroup, *http.Response, error) Update(ctx context.Context, fwGroupID string, fwGroupReq *FirewallGroupReq) error @@ -110,7 +110,7 @@ func (f *FireWallGroupServiceHandler) Delete(ctx context.Context, fwGroupID stri } // List will return a list of all firewall groups on your Vultr account -func (f *FireWallGroupServiceHandler) List(ctx context.Context, options *ListOptions) ([]FirewallGroup, *Meta, *http.Response, error) { +func (f *FireWallGroupServiceHandler) List(ctx context.Context, options *ListOptions) ([]FirewallGroup, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/firewalls" req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/firewall_rule.go b/firewall_rule.go index 1b5a544..727b6a0 100644 --- a/firewall_rule.go +++ b/firewall_rule.go @@ -58,7 +58,7 @@ type firewallRuleBase struct { } // Create will create a rule in a firewall group. -func (f *FireWallRuleServiceHandler) Create(ctx context.Context, fwGroupID string, fwRuleReq *FirewallRuleReq) (*FirewallRule, *http.Response, error) { +func (f *FireWallRuleServiceHandler) Create(ctx context.Context, fwGroupID string, fwRuleReq *FirewallRuleReq) (*FirewallRule, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("/v2/firewalls/%s/rules", fwGroupID) req, err := f.client.NewRequest(ctx, http.MethodPost, uri, fwRuleReq) @@ -106,7 +106,7 @@ func (f *FireWallRuleServiceHandler) Delete(ctx context.Context, fwGroupID strin } // List will return both ipv4 an ipv6 firewall rules that are defined within a firewall group -func (f *FireWallRuleServiceHandler) List(ctx context.Context, fwGroupID string, options *ListOptions) ([]FirewallRule, *Meta, *http.Response, error) { +func (f *FireWallRuleServiceHandler) List(ctx context.Context, fwGroupID string, options *ListOptions) ([]FirewallRule, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("/v2/firewalls/%s/rules", fwGroupID) req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/govultr.go b/govultr.go index 4bec59e..c6365b7 100644 --- a/govultr.go +++ b/govultr.go @@ -153,7 +153,7 @@ func (c *Client) NewRequest(ctx context.Context, method, uri string, body interf } } - req, err := http.NewRequest(method, resolvedURL.String(), buf) + req, err := http.NewRequestWithContext(ctx, method, resolvedURL.String(), buf) if err != nil { return nil, err } diff --git a/govultr_test.go b/govultr_test.go index f4e82e9..a9a4685 100644 --- a/govultr_test.go +++ b/govultr_test.go @@ -27,8 +27,8 @@ func setup() { server = httptest.NewServer(mux) client = NewClient(nil) - url, _ := url.Parse(server.URL) - client.BaseURL = url + thisURL, _ := url.Parse(server.URL) + client.BaseURL = thisURL } func teardown() { @@ -43,10 +43,6 @@ func TestNewClient(t *testing.T) { t.Errorf("NewClient BaseURL = %v, expected %v", client.BaseURL, server.URL) } - //if client != "dummy-key" { - // t.Errorf("NewClient ApiKey = %v, expected %v", client.APIKey.key, "dummy-key") - //} - if client.UserAgent != userAgent { t.Errorf("NewClient UserAgent = %v, expected %v", client.UserAgent, userAgent) } @@ -78,7 +74,6 @@ func TestClient_DoWithContext(t *testing.T) { t.Errorf("Request method = %v, expecting %v", request.Method, method) } fmt.Fprint(writer, `{"Bird":"vultr"}`) - }) req, _ := client.NewRequest(ctx, http.MethodGet, "/", nil) @@ -141,7 +136,7 @@ func TestClient_DoWithContextError(t *testing.T) { panicked = fmt.Sprint(err) } }() - client.DoWithContext(context.Background(), req, nil) //nolint:all + client.DoWithContext(context.Background(), req, nil) }() if panicked != "" { t.Errorf("unexpected panic: %s", panicked) @@ -177,7 +172,6 @@ func TestClient_NewRequest(t *testing.T) { if contentType != "application/json" { t.Errorf("NewRequest() Header Content Type = %v, expected %v", contentType, "application/x-www-form-urlencoded") } - } func TestClient_SetBaseUrl(t *testing.T) { @@ -216,11 +210,11 @@ func TestClient_SetRateLimit(t *testing.T) { setup() defer teardown() - time := 600 * time.Millisecond - client.SetRateLimit(time) + tTime := 600 * time.Millisecond + client.SetRateLimit(tTime) - if client.client.RetryWaitMax != time { - t.Errorf("NewClient max RateLimit = %v, expected %v", client.client.RetryWaitMax, time) + if client.client.RetryWaitMax != tTime { + t.Errorf("NewClient max RateLimit = %v, expected %v", client.client.RetryWaitMax, tTime) } } diff --git a/instance.go b/instance.go index b3f8d2d..d4ae9d0 100644 --- a/instance.go +++ b/instance.go @@ -327,7 +327,7 @@ func (i *InstanceServiceHandler) Get(ctx context.Context, instanceID string) (*I } // Update will update the server with the given parameters -func (i *InstanceServiceHandler) Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) (*Instance, *http.Response, error) { +func (i *InstanceServiceHandler) Update(ctx context.Context, instanceID string, instanceReq *InstanceUpdateReq) (*Instance, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodPatch, uri, instanceReq) @@ -358,7 +358,7 @@ func (i *InstanceServiceHandler) Delete(ctx context.Context, instanceID string) } // List all instances on your account. -func (i *InstanceServiceHandler) List(ctx context.Context, options *ListOptions) ([]Instance, *Meta, *http.Response, error) { +func (i *InstanceServiceHandler) List(ctx context.Context, options *ListOptions) ([]Instance, *Meta, *http.Response, error) { //nolint:dupl req, err := i.client.NewRequest(ctx, http.MethodGet, instancePath, nil) if err != nil { return nil, nil, nil, err @@ -417,7 +417,7 @@ func (i *InstanceServiceHandler) Reboot(ctx context.Context, instanceID string) } // Reinstall an instance. -func (i *InstanceServiceHandler) Reinstall(ctx context.Context, instanceID string, reinstallReq *ReinstallReq) (*Instance, *http.Response, error) { +func (i *InstanceServiceHandler) Reinstall(ctx context.Context, instanceID string, reinstallReq *ReinstallReq) (*Instance, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/reinstall", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodPost, uri, reinstallReq) @@ -520,7 +520,7 @@ func (i *InstanceServiceHandler) GetNeighbors(ctx context.Context, instanceID st // ListPrivateNetworks currently attached to an instance. // Deprecated: ListPrivateNetworks should no longer be used. Instead, use ListVPCInfo -func (i *InstanceServiceHandler) ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, *http.Response, error) { +func (i *InstanceServiceHandler) ListPrivateNetworks(ctx context.Context, instanceID string, options *ListOptions) ([]PrivateNetwork, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/private-networks", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -574,7 +574,7 @@ func (i *InstanceServiceHandler) DetachPrivateNetwork(ctx context.Context, insta } // ListVPCInfo currently attached to an instance. -func (i *InstanceServiceHandler) ListVPCInfo(ctx context.Context, instanceID string, options *ListOptions) ([]VPCInfo, *Meta, *http.Response, error) { +func (i *InstanceServiceHandler) ListVPCInfo(ctx context.Context, instanceID string, options *ListOptions) ([]VPCInfo, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/vpcs", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -684,7 +684,7 @@ func (i *InstanceServiceHandler) GetBackupSchedule(ctx context.Context, instance } // SetBackupSchedule sets the backup schedule for a given instance - all time values are in UTC. -func (i *InstanceServiceHandler) SetBackupSchedule(ctx context.Context, instanceID string, backup *BackupScheduleReq) (*http.Response, error) { +func (i *InstanceServiceHandler) SetBackupSchedule(ctx context.Context, instanceID string, backup *BackupScheduleReq) (*http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s/backup-schedule", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodPost, uri, backup) if err != nil { @@ -715,7 +715,7 @@ func (i *InstanceServiceHandler) CreateIPv4(ctx context.Context, instanceID stri } // ListIPv4 addresses that are currently assigned to a given instance. -func (i *InstanceServiceHandler) ListIPv4(ctx context.Context, instanceID string, options *ListOptions) ([]IPv4, *Meta, *http.Response, error) { +func (i *InstanceServiceHandler) ListIPv4(ctx context.Context, instanceID string, options *ListOptions) ([]IPv4, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/ipv4", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { @@ -750,7 +750,7 @@ func (i *InstanceServiceHandler) DeleteIPv4(ctx context.Context, instanceID, ip } // ListIPv6 addresses that are currently assigned to a given instance. -func (i *InstanceServiceHandler) ListIPv6(ctx context.Context, instanceID string, options *ListOptions) ([]IPv6, *Meta, *http.Response, error) { +func (i *InstanceServiceHandler) ListIPv6(ctx context.Context, instanceID string, options *ListOptions) ([]IPv6, *Meta, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/ipv6", instancePath, instanceID) req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { diff --git a/instance_test.go b/instance_test.go index 342800d..90955d8 100644 --- a/instance_test.go +++ b/instance_test.go @@ -8,6 +8,42 @@ import ( "testing" ) +const ( + defaultInstanceListResponse string = `{ + "instance": { + "id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", + "os": "CentOS SELinux 8 x64", + "ram": 2048, + "disk": 60, + "main_ip": "123.123.123.123", + "vcpu_count": 2, + "region": "ewr", + "plan": "vc2-1c-2gb", + "date_created": "2013-12-19 14:45:41", + "status": "active", + "allowed_bandwidth": 2000, + "netmask_v4": "255.255.255.248", + "gateway_v4": "123.123.123.1", + "power_status": "running", + "server_status": "ok", + "v6_network": "2001:DB8:1000::", + "v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000", + "v6_network_size": 64, + "label": "my new server", + "internal_ip": "10.99.0.10", + "kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", + "default_password" : "nreqnusibni", + "tags": ["my tag"], + "os_id": 362, + "app_id": 0, + "firewall_group_id": "1234", + "features": [ + "auto_backups", "ipv6" + ] + } + }` +) + func TestServerServiceHandler_GetBackupSchedule(t *testing.T) { setup() defer teardown() @@ -522,40 +558,7 @@ func TestServerServiceHandler_Reinstall(t *testing.T) { defer teardown() mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33/reinstall", func(writer http.ResponseWriter, request *http.Request) { - response := `{ - "instance": { - "id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", - "os": "CentOS SELinux 8 x64", - "ram": 2048, - "disk": 60, - "main_ip": "123.123.123.123", - "vcpu_count": 2, - "region": "ewr", - "plan": "vc2-1c-2gb", - "date_created": "2013-12-19 14:45:41", - "status": "active", - "allowed_bandwidth": 2000, - "netmask_v4": "255.255.255.248", - "gateway_v4": "123.123.123.1", - "power_status": "running", - "server_status": "ok", - "v6_network": "2001:DB8:1000::", - "v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000", - "v6_network_size": 64, - "label": "my new server", - "internal_ip": "10.99.0.10", - "kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", - "default_password" : "nreqnusibni", - "tags": ["my tag"], - "os_id": 362, - "app_id": 0, - "firewall_group_id": "1234", - "features": [ - "auto_backups", "ipv6" - ] - } - }` - fmt.Fprint(writer, response) + fmt.Fprint(writer, defaultInstanceListResponse) }) instanceRes, _, err := client.Instance.Reinstall(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", nil) @@ -618,40 +621,7 @@ func TestServerServiceHandler_Create(t *testing.T) { defer teardown() mux.HandleFunc("/v2/instances", func(writer http.ResponseWriter, request *http.Request) { - response := `{ - "instance": { - "id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", - "os": "CentOS SELinux 8 x64", - "ram": 2048, - "disk": 60, - "main_ip": "123.123.123.123", - "vcpu_count": 2, - "region": "ewr", - "plan": "vc2-1c-2gb", - "date_created": "2013-12-19 14:45:41", - "status": "active", - "allowed_bandwidth": 2000, - "netmask_v4": "255.255.255.248", - "gateway_v4": "123.123.123.1", - "power_status": "running", - "server_status": "ok", - "v6_network": "2001:DB8:1000::", - "v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000", - "v6_network_size": 64, - "label": "my new server", - "internal_ip": "10.99.0.10", - "kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", - "default_password" : "nreqnusibni", - "tags": ["my tag"], - "os_id": 362, - "app_id": 0, - "firewall_group_id": "1234", - "features": [ - "auto_backups", "ipv6" - ] - } - }` - fmt.Fprint(writer, response) + fmt.Fprint(writer, defaultInstanceListResponse) }) options := &InstanceCreateReq{ @@ -678,8 +648,6 @@ func TestServerServiceHandler_Create(t *testing.T) { t.Errorf("Instance.Create returned %+v", err) } - features := []string{"auto_backups", "ipv6"} - expected := &Instance{ ID: "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", Os: "CentOS SELinux 8 x64", @@ -707,7 +675,7 @@ func TestServerServiceHandler_Create(t *testing.T) { Tags: []string{"my tag"}, AppID: 0, FirewallGroupID: "1234", - Features: features, + Features: []string{"auto_backups", "ipv6"}, } if !reflect.DeepEqual(server, expected) { @@ -824,40 +792,7 @@ func TestServerServiceHandler_GetServer(t *testing.T) { defer teardown() mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33", func(writer http.ResponseWriter, request *http.Request) { - response := `{ - "instance": { - "id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", - "os": "CentOS SELinux 8 x64", - "ram": 2048, - "disk": 60, - "main_ip": "123.123.123.123", - "vcpu_count": 2, - "region": "ewr", - "plan": "vc2-1c-2gb", - "date_created": "2013-12-19 14:45:41", - "status": "active", - "allowed_bandwidth": 2000, - "netmask_v4": "255.255.255.248", - "gateway_v4": "123.123.123.1", - "power_status": "running", - "server_status": "ok", - "v6_network": "2001:DB8:1000::", - "v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000", - "v6_network_size": 64, - "label": "my new server", - "internal_ip": "10.99.0.10", - "kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", - "default_password" : "nreqnusibni", - "tags": ["my tag"], - "os_id": 362, - "app_id": 0, - "firewall_group_id": "", - "features": [ - "auto_backups" - ] - } - }` - fmt.Fprint(writer, response) + fmt.Fprint(writer, defaultInstanceListResponse) }) server, _, err := client.Instance.Get(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33") @@ -865,8 +800,6 @@ func TestServerServiceHandler_GetServer(t *testing.T) { t.Errorf("Instance.GetServer returned %+v", err) } - features := []string{"auto_backups"} - expected := &Instance{ ID: "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", Os: "CentOS SELinux 8 x64", @@ -893,8 +826,8 @@ func TestServerServiceHandler_GetServer(t *testing.T) { KVM: "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", Tags: []string{"my tag"}, AppID: 0, - FirewallGroupID: "", - Features: features, + FirewallGroupID: "1234", + Features: []string{"auto_backups", "ipv6"}, } if !reflect.DeepEqual(server, expected) { @@ -1110,40 +1043,7 @@ func TestServerServiceHandler_Update(t *testing.T) { defer teardown() mux.HandleFunc("/v2/instances/14b3e7d6-ffb5-4994-8502-57fcd9db3b33", func(writer http.ResponseWriter, request *http.Request) { - response := `{ - "instance": { - "id": "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", - "os": "CentOS SELinux 8 x64", - "ram": 2048, - "disk": 60, - "main_ip": "123.123.123.123", - "vcpu_count": 2, - "region": "ewr", - "plan": "vc2-1c-2gb", - "date_created": "2013-12-19 14:45:41", - "status": "active", - "allowed_bandwidth": 2000, - "netmask_v4": "255.255.255.248", - "gateway_v4": "123.123.123.1", - "power_status": "running", - "server_status": "ok", - "v6_network": "2001:DB8:1000::", - "v6_main_ip": "fd11:1111:1112:1c02:0200:00ff:fe00:0000", - "v6_network_size": 64, - "label": "my new server", - "internal_ip": "10.99.0.10", - "kvm": "https://my.vultr.com/subs/novnc/api.php?data=eawxFVZw2mXnhGUV", - "default_password" : "nreqnusibni", - "tags": ["my tag"], - "os_id": 362, - "app_id": 0, - "firewall_group_id": "1234", - "features": [ - "auto_backups", "ipv6" - ] - } - }` - fmt.Fprint(writer, response) + fmt.Fprint(writer, defaultInstanceListResponse) }) options := &InstanceUpdateReq{ diff --git a/iso.go b/iso.go index a30ec77..7fbc947 100644 --- a/iso.go +++ b/iso.go @@ -110,7 +110,7 @@ func (i *ISOServiceHandler) Delete(ctx context.Context, isoID string) error { } // List will list all ISOs currently available on your account -func (i *ISOServiceHandler) List(ctx context.Context, options *ListOptions) ([]ISO, *Meta, *http.Response, error) { +func (i *ISOServiceHandler) List(ctx context.Context, options *ListOptions) ([]ISO, *Meta, *http.Response, error) { //nolint:dupl uri := "/v2/iso" req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -135,7 +135,7 @@ func (i *ISOServiceHandler) List(ctx context.Context, options *ListOptions) ([]I } // ListPublic will list public ISOs offered in the Vultr ISO library. -func (i *ISOServiceHandler) ListPublic(ctx context.Context, options *ListOptions) ([]PublicISO, *Meta, *http.Response, error) { +func (i *ISOServiceHandler) ListPublic(ctx context.Context, options *ListOptions) ([]PublicISO, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/iso-public" req, err := i.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/kubernetes.go b/kubernetes.go index eb1c040..0dcb941 100644 --- a/kubernetes.go +++ b/kubernetes.go @@ -184,7 +184,7 @@ func (k *KubernetesHandler) GetCluster(ctx context.Context, id string) (*Cluster } // ListClusters will return all kubernetes clusters. -func (k *KubernetesHandler) ListClusters(ctx context.Context, options *ListOptions) ([]Cluster, *Meta, *http.Response, error) { +func (k *KubernetesHandler) ListClusters(ctx context.Context, options *ListOptions) ([]Cluster, *Meta, *http.Response, error) { //nolint:dupl,lll req, err := k.client.NewRequest(ctx, http.MethodGet, vkePath, nil) if err != nil { return nil, nil, nil, err @@ -254,7 +254,7 @@ func (k *KubernetesHandler) CreateNodePool(ctx context.Context, vkeID string, no } // ListNodePools will return all nodepools for a given VKE cluster -func (k *KubernetesHandler) ListNodePools(ctx context.Context, vkeID string, options *ListOptions) ([]NodePool, *Meta, *http.Response, error) { +func (k *KubernetesHandler) ListNodePools(ctx context.Context, vkeID string, options *ListOptions) ([]NodePool, *Meta, *http.Response, error) { //nolint:lll req, err := k.client.NewRequest(ctx, http.MethodGet, fmt.Sprintf("%s/%s/node-pools", vkePath, vkeID), nil) if err != nil { return nil, nil, nil, err @@ -293,7 +293,7 @@ func (k *KubernetesHandler) GetNodePool(ctx context.Context, vkeID, nodePoolID s } // UpdateNodePool will allow you change the quantity of nodes within a nodepool -func (k *KubernetesHandler) UpdateNodePool(ctx context.Context, vkeID, nodePoolID string, updateReq *NodePoolReqUpdate) (*NodePool, *http.Response, error) { +func (k *KubernetesHandler) UpdateNodePool(ctx context.Context, vkeID, nodePoolID string, updateReq *NodePoolReqUpdate) (*NodePool, *http.Response, error) { //nolint:lll req, err := k.client.NewRequest(ctx, http.MethodPatch, fmt.Sprintf("%s/%s/node-pools/%s", vkePath, vkeID, nodePoolID), updateReq) if err != nil { return nil, nil, err @@ -321,7 +321,12 @@ func (k *KubernetesHandler) DeleteNodePool(ctx context.Context, vkeID, nodePoolI // DeleteNodePoolInstance will remove a specified node from a nodepool func (k *KubernetesHandler) DeleteNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error { - req, err := k.client.NewRequest(ctx, http.MethodDelete, fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s", vkePath, vkeID, nodePoolID, nodeID), nil) + req, err := k.client.NewRequest( + ctx, + http.MethodDelete, + fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s", vkePath, vkeID, nodePoolID, nodeID), + nil, + ) if err != nil { return err } @@ -332,7 +337,12 @@ func (k *KubernetesHandler) DeleteNodePoolInstance(ctx context.Context, vkeID, n // RecycleNodePoolInstance will recycle (destroy + redeploy) a given node on a nodepool func (k *KubernetesHandler) RecycleNodePoolInstance(ctx context.Context, vkeID, nodePoolID, nodeID string) error { - req, err := k.client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s/recycle", vkePath, vkeID, nodePoolID, nodeID), nil) + req, err := k.client.NewRequest( + ctx, + http.MethodPost, + fmt.Sprintf("%s/%s/node-pools/%s/nodes/%s/recycle", vkePath, vkeID, nodePoolID, nodeID), + nil, + ) if err != nil { return err } @@ -392,7 +402,6 @@ func (k *KubernetesHandler) GetUpgrades(ctx context.Context, vkeID string) ([]st // Upgrade beings a VKE cluster upgrade func (k *KubernetesHandler) Upgrade(ctx context.Context, vkeID string, body *ClusterUpgradeReq) error { - req, err := k.client.NewRequest(ctx, http.MethodPost, fmt.Sprintf("%s/%s/upgrades", vkePath, vkeID), body) if err != nil { return err diff --git a/kubernetes_test.go b/kubernetes_test.go index c0e7015..22f9620 100644 --- a/kubernetes_test.go +++ b/kubernetes_test.go @@ -313,8 +313,7 @@ func TestKubernetesHandler_ListClusters(t *testing.T) { c, can := context.WithTimeout(ctx, 1*time.Microsecond) defer can() - _, _, _, err = client.Kubernetes.ListClusters(c, nil) - if err == nil { + if _, _, _, err = client.Kubernetes.ListClusters(c, nil); err == nil { t.Error("Kubernetes.ListClusters returned nil") } } @@ -587,8 +586,7 @@ func TestKubernetesHandler_ListNodePools(t *testing.T) { c, can := context.WithTimeout(ctx, 1*time.Microsecond) defer can() - _, _, _, err = client.Kubernetes.ListNodePools(c, "1", nil) - if err == nil { + if _, _, _, err = client.Kubernetes.ListNodePools(c, "1", nil); err == nil { t.Error("Kubernetes.ListNodePools returned nil") } } diff --git a/load_balancer.go b/load_balancer.go index 16b2c2a..5135758 100644 --- a/load_balancer.go +++ b/load_balancer.go @@ -14,16 +14,16 @@ const lbPath = "/v2/load-balancers" // Link : https://www.vultr.com/api/#tag/load-balancer type LoadBalancerService interface { Create(ctx context.Context, createReq *LoadBalancerReq) (*LoadBalancer, *http.Response, error) - Get(ctx context.Context, ID string) (*LoadBalancer, *http.Response, error) - Update(ctx context.Context, ID string, updateReq *LoadBalancerReq) error - Delete(ctx context.Context, ID string) error + Get(ctx context.Context, lbID string) (*LoadBalancer, *http.Response, error) + Update(ctx context.Context, lbID string, updateReq *LoadBalancerReq) error + Delete(ctx context.Context, lbID string) error List(ctx context.Context, options *ListOptions) ([]LoadBalancer, *Meta, *http.Response, error) - CreateForwardingRule(ctx context.Context, ID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error) - GetForwardingRule(ctx context.Context, ID string, ruleID string) (*ForwardingRule, *http.Response, error) - DeleteForwardingRule(ctx context.Context, ID string, RuleID string) error - ListForwardingRules(ctx context.Context, ID string, options *ListOptions) ([]ForwardingRule, *Meta, *http.Response, error) - ListFirewallRules(ctx context.Context, ID string, options *ListOptions) ([]LBFirewallRule, *Meta, *http.Response, error) - GetFirewallRule(ctx context.Context, ID string, ruleID string) (*LBFirewallRule, *http.Response, error) + CreateForwardingRule(ctx context.Context, lbID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error) + GetForwardingRule(ctx context.Context, lbID string, ruleID string) (*ForwardingRule, *http.Response, error) + DeleteForwardingRule(ctx context.Context, lbID string, RuleID string) error + ListForwardingRules(ctx context.Context, lbID string, options *ListOptions) ([]ForwardingRule, *Meta, *http.Response, error) + ListFirewallRules(ctx context.Context, lbID string, options *ListOptions) ([]LBFirewallRule, *Meta, *http.Response, error) + GetFirewallRule(ctx context.Context, lbID string, ruleID string) (*LBFirewallRule, *http.Response, error) } // LoadBalancerHandler handles interaction with the server methods for the Vultr API @@ -173,8 +173,8 @@ func (l *LoadBalancerHandler) Create(ctx context.Context, createReq *LoadBalance } // Get a load balancer -func (l *LoadBalancerHandler) Get(ctx context.Context, ID string) (*LoadBalancer, *http.Response, error) { - uri := fmt.Sprintf("%s/%s", lbPath, ID) +func (l *LoadBalancerHandler) Get(ctx context.Context, lbID string) (*LoadBalancer, *http.Response, error) { + uri := fmt.Sprintf("%s/%s", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, err @@ -190,8 +190,8 @@ func (l *LoadBalancerHandler) Get(ctx context.Context, ID string) (*LoadBalancer } // Update updates your your load balancer -func (l *LoadBalancerHandler) Update(ctx context.Context, ID string, updateReq *LoadBalancerReq) error { - uri := fmt.Sprintf("%s/%s", lbPath, ID) +func (l *LoadBalancerHandler) Update(ctx context.Context, lbID string, updateReq *LoadBalancerReq) error { + uri := fmt.Sprintf("%s/%s", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodPatch, uri, updateReq) if err != nil { return err @@ -202,8 +202,8 @@ func (l *LoadBalancerHandler) Update(ctx context.Context, ID string, updateReq * } // Delete a load balancer subscription. -func (l *LoadBalancerHandler) Delete(ctx context.Context, ID string) error { - uri := fmt.Sprintf("%s/%s", lbPath, ID) +func (l *LoadBalancerHandler) Delete(ctx context.Context, lbID string) error { + uri := fmt.Sprintf("%s/%s", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil) if err != nil { return err @@ -213,7 +213,7 @@ func (l *LoadBalancerHandler) Delete(ctx context.Context, ID string) error { } // List all load balancer subscriptions on the current account. -func (l *LoadBalancerHandler) List(ctx context.Context, options *ListOptions) ([]LoadBalancer, *Meta, *http.Response, error) { +func (l *LoadBalancerHandler) List(ctx context.Context, options *ListOptions) ([]LoadBalancer, *Meta, *http.Response, error) { //nolint:dupl req, err := l.client.NewRequest(ctx, http.MethodGet, lbPath, nil) if err != nil { return nil, nil, nil, err @@ -237,8 +237,8 @@ func (l *LoadBalancerHandler) List(ctx context.Context, options *ListOptions) ([ // CreateForwardingRule will create a new forwarding rule for your load balancer subscription. // Note the RuleID will be returned in the ForwardingRule struct -func (l *LoadBalancerHandler) CreateForwardingRule(ctx context.Context, ID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error) { - uri := fmt.Sprintf("%s/%s/forwarding-rules", lbPath, ID) +func (l *LoadBalancerHandler) CreateForwardingRule(ctx context.Context, lbID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error) { //nolint:lll + uri := fmt.Sprintf("%s/%s/forwarding-rules", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodPost, uri, rule) if err != nil { return nil, nil, err @@ -254,8 +254,8 @@ func (l *LoadBalancerHandler) CreateForwardingRule(ctx context.Context, ID strin } // GetForwardingRule will get a forwarding rule from your load balancer subscription. -func (l *LoadBalancerHandler) GetForwardingRule(ctx context.Context, ID string, ruleID string) (*ForwardingRule, *http.Response, error) { - uri := fmt.Sprintf("%s/%s/forwarding-rules/%s", lbPath, ID, ruleID) +func (l *LoadBalancerHandler) GetForwardingRule(ctx context.Context, lbID, ruleID string) (*ForwardingRule, *http.Response, error) { + uri := fmt.Sprintf("%s/%s/forwarding-rules/%s", lbPath, lbID, ruleID) req, err := l.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, err @@ -271,8 +271,8 @@ func (l *LoadBalancerHandler) GetForwardingRule(ctx context.Context, ID string, } // ListForwardingRules lists all forwarding rules for a load balancer subscription -func (l *LoadBalancerHandler) ListForwardingRules(ctx context.Context, ID string, options *ListOptions) ([]ForwardingRule, *Meta, *http.Response, error) { - uri := fmt.Sprintf("%s/%s/forwarding-rules", lbPath, ID) +func (l *LoadBalancerHandler) ListForwardingRules(ctx context.Context, lbID string, options *ListOptions) ([]ForwardingRule, *Meta, *http.Response, error) { //nolint:dupl,lll + uri := fmt.Sprintf("%s/%s/forwarding-rules", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, nil, err @@ -295,8 +295,8 @@ func (l *LoadBalancerHandler) ListForwardingRules(ctx context.Context, ID string } // DeleteForwardingRule removes a forwarding rule from a load balancer subscription -func (l *LoadBalancerHandler) DeleteForwardingRule(ctx context.Context, ID string, RuleID string) error { - uri := fmt.Sprintf("%s/%s/forwarding-rules/%s", lbPath, ID, RuleID) +func (l *LoadBalancerHandler) DeleteForwardingRule(ctx context.Context, lbID, ruleID string) error { + uri := fmt.Sprintf("%s/%s/forwarding-rules/%s", lbPath, lbID, ruleID) req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil) if err != nil { return err @@ -307,8 +307,8 @@ func (l *LoadBalancerHandler) DeleteForwardingRule(ctx context.Context, ID strin } // GetFirewallRule will get a firewall rule from your load balancer subscription. -func (l *LoadBalancerHandler) GetFirewallRule(ctx context.Context, ID string, ruleID string) (*LBFirewallRule, *http.Response, error) { - uri := fmt.Sprintf("%s/%s/firewall-rules/%s", lbPath, ID, ruleID) +func (l *LoadBalancerHandler) GetFirewallRule(ctx context.Context, lbID, ruleID string) (*LBFirewallRule, *http.Response, error) { + uri := fmt.Sprintf("%s/%s/firewall-rules/%s", lbPath, lbID, ruleID) req, err := l.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, err @@ -324,8 +324,8 @@ func (l *LoadBalancerHandler) GetFirewallRule(ctx context.Context, ID string, ru } // ListFirewallRules lists all firewall rules for a load balancer subscription -func (l *LoadBalancerHandler) ListFirewallRules(ctx context.Context, ID string, options *ListOptions) ([]LBFirewallRule, *Meta, *http.Response, error) { - uri := fmt.Sprintf("%s/%s/firewall-rules", lbPath, ID) +func (l *LoadBalancerHandler) ListFirewallRules(ctx context.Context, lbID string, options *ListOptions) ([]LBFirewallRule, *Meta, *http.Response, error) { //nolint:dupl,lll + uri := fmt.Sprintf("%s/%s/firewall-rules", lbPath, lbID) req, err := l.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { return nil, nil, nil, err diff --git a/load_balancer_test.go b/load_balancer_test.go index 47f2e70..e4aff8f 100644 --- a/load_balancer_test.go +++ b/load_balancer_test.go @@ -147,7 +147,6 @@ func TestLoadBalancerHandler_List(t *testing.T) { if !reflect.DeepEqual(meta, expectedMeta) { t.Errorf("LoadBalancer.List returned %+v, expected %+v", meta, expectedMeta) } - } func TestLoadBalancerHandler_Delete(t *testing.T) { diff --git a/network.go b/network.go index dd195ce..1b9a146 100644 --- a/network.go +++ b/network.go @@ -1,4 +1,4 @@ -package govultr +package govultr //nolint:dupl import ( "context" @@ -98,7 +98,7 @@ func (n *NetworkServiceHandler) Get(ctx context.Context, networkID string) (*Net // Update updates a private network // Deprecated: NetworkServiceHandler Update should no longer be used. Instead, use VPCServiceHandler Update. -func (n *NetworkServiceHandler) Update(ctx context.Context, networkID string, description string) error { +func (n *NetworkServiceHandler) Update(ctx context.Context, networkID, description string) error { uri := fmt.Sprintf("%s/%s", netPath, networkID) netReq := RequestBody{"description": description} @@ -125,7 +125,7 @@ func (n *NetworkServiceHandler) Delete(ctx context.Context, networkID string) er // List lists all private networks on the current account // Deprecated: NetworkServiceHandler List should no longer be used. Instead, use VPCServiceHandler List. -func (n *NetworkServiceHandler) List(ctx context.Context, options *ListOptions) ([]Network, *Meta, *http.Response, error) { +func (n *NetworkServiceHandler) List(ctx context.Context, options *ListOptions) ([]Network, *Meta, *http.Response, error) { //nolint:dupl req, err := n.client.NewRequest(ctx, http.MethodGet, netPath, nil) if err != nil { return nil, nil, nil, err diff --git a/object_storage.go b/object_storage.go index aaeb790..1597fcd 100644 --- a/object_storage.go +++ b/object_storage.go @@ -71,12 +71,6 @@ type s3KeysBase struct { S3Credentials *S3Keys `json:"s3_credentials"` } -//// ObjectListOptions are your optional params you have available to list data. -//type ObjectListOptions struct { -// IncludeS3 bool -// Label string -//} - // Create an object storage subscription func (o *ObjectStorageServiceHandler) Create(ctx context.Context, clusterID int, label string) (*ObjectStorage, *http.Response, error) { uri := "/v2/object-storage" @@ -142,7 +136,7 @@ func (o *ObjectStorageServiceHandler) Delete(ctx context.Context, id string) err } // List all object storage subscriptions on the current account. This includes both pending and active subscriptions. -func (o *ObjectStorageServiceHandler) List(ctx context.Context, options *ListOptions) ([]ObjectStorage, *Meta, *http.Response, error) { +func (o *ObjectStorageServiceHandler) List(ctx context.Context, options *ListOptions) ([]ObjectStorage, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/object-storage" req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) @@ -168,7 +162,7 @@ func (o *ObjectStorageServiceHandler) List(ctx context.Context, options *ListOpt // ListCluster returns back your object storage clusters. // Clusters may be removed over time. The "deploy" field can be used to determine whether or not new deployments are allowed in the cluster. -func (o *ObjectStorageServiceHandler) ListCluster(ctx context.Context, options *ListOptions) ([]ObjectStorageCluster, *Meta, *http.Response, error) { +func (o *ObjectStorageServiceHandler) ListCluster(ctx context.Context, options *ListOptions) ([]ObjectStorageCluster, *Meta, *http.Response, error) { //nolint:lll uri := "/v2/object-storage/clusters" req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { diff --git a/os.go b/os.go index cc3caa1..c1ffa0c 100644 --- a/os.go +++ b/os.go @@ -34,7 +34,7 @@ type osBase struct { var _ OSService = &OSServiceHandler{} // List retrieves a list of available operating systems. -func (o *OSServiceHandler) List(ctx context.Context, options *ListOptions) ([]OS, *Meta, *http.Response, error) { +func (o *OSServiceHandler) List(ctx context.Context, options *ListOptions) ([]OS, *Meta, *http.Response, error) { //nolint:dupl uri := "/v2/os" req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) if err != nil { diff --git a/plans.go b/plans.go index 88716ec..19f7ea4 100644 --- a/plans.go +++ b/plans.go @@ -90,7 +90,7 @@ func (p *PlanServiceHandler) List(ctx context.Context, planType string, options } // ListBareMetal all active bare metal plans. -func (p *PlanServiceHandler) ListBareMetal(ctx context.Context, options *ListOptions) ([]BareMetalPlan, *Meta, *http.Response, error) { +func (p *PlanServiceHandler) ListBareMetal(ctx context.Context, options *ListOptions) ([]BareMetalPlan, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/plans-metal" req, err := p.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/regions.go b/regions.go index 85c6dce..e89655c 100644 --- a/regions.go +++ b/regions.go @@ -67,7 +67,7 @@ func (r *RegionServiceHandler) List(ctx context.Context, options *ListOptions) ( } // Availability retrieves a list of the plan IDs currently available for a given location. -func (r *RegionServiceHandler) Availability(ctx context.Context, regionID string, planType string) (*PlanAvailability, *http.Response, error) { +func (r *RegionServiceHandler) Availability(ctx context.Context, regionID, planType string) (*PlanAvailability, *http.Response, error) { uri := fmt.Sprintf("/v2/regions/%s/availability", regionID) req, err := r.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/reserved_ip.go b/reserved_ip.go index 9d90ffc..fd1fc4c 100644 --- a/reserved_ip.go +++ b/reserved_ip.go @@ -86,7 +86,7 @@ func (r *ReservedIPServiceHandler) Create(ctx context.Context, ripCreate *Reserv } // Update updates label on the Reserved IP -func (r *ReservedIPServiceHandler) Update(ctx context.Context, id string, ripUpdate *ReservedIPUpdateReq) (*ReservedIP, *http.Response, error) { +func (r *ReservedIPServiceHandler) Update(ctx context.Context, id string, ripUpdate *ReservedIPUpdateReq) (*ReservedIP, *http.Response, error) { //nolint:lll uri := fmt.Sprintf("%s/%s", ripPath, id) req, err := r.client.NewRequest(ctx, http.MethodPatch, uri, ripUpdate) if err != nil { @@ -132,7 +132,7 @@ func (r *ReservedIPServiceHandler) Delete(ctx context.Context, id string) error } // List lists all the reserved IPs associated with your Vultr account -func (r *ReservedIPServiceHandler) List(ctx context.Context, options *ListOptions) ([]ReservedIP, *Meta, *http.Response, error) { +func (r *ReservedIPServiceHandler) List(ctx context.Context, options *ListOptions) ([]ReservedIP, *Meta, *http.Response, error) { //nolint:dupl,lll req, err := r.client.NewRequest(ctx, http.MethodGet, ripPath, nil) if err != nil { return nil, nil, nil, err diff --git a/snapshot.go b/snapshot.go index 8ec108a..8ee82ba 100644 --- a/snapshot.go +++ b/snapshot.go @@ -124,7 +124,7 @@ func (s *SnapshotServiceHandler) Delete(ctx context.Context, snapshotID string) } // List all available snapshots. -func (s *SnapshotServiceHandler) List(ctx context.Context, options *ListOptions) ([]Snapshot, *Meta, *http.Response, error) { +func (s *SnapshotServiceHandler) List(ctx context.Context, options *ListOptions) ([]Snapshot, *Meta, *http.Response, error) { //nolint:dupl uri := "/v2/snapshots" req, err := s.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/ssh_key.go b/ssh_key.go index 62c0c85..27bb2fd 100644 --- a/ssh_key.go +++ b/ssh_key.go @@ -10,7 +10,7 @@ import ( // SSHKeyService is the interface to interact with the SSH Key endpoints on the Vultr API // Link : https://www.vultr.com/api/#tag/ssh -type SSHKeyService interface { +type SSHKeyService interface { //nolint:dupl Create(ctx context.Context, sshKeyReq *SSHKeyReq) (*SSHKey, *http.Response, error) Get(ctx context.Context, sshKeyID string) (*SSHKey, *http.Response, error) Update(ctx context.Context, sshKeyID string, sshKeyReq *SSHKeyReq) error @@ -108,7 +108,7 @@ func (s *SSHKeyServiceHandler) Delete(ctx context.Context, sshKeyID string) erro } // List all available SSH Keys. -func (s *SSHKeyServiceHandler) List(ctx context.Context, options *ListOptions) ([]SSHKey, *Meta, *http.Response, error) { +func (s *SSHKeyServiceHandler) List(ctx context.Context, options *ListOptions) ([]SSHKey, *Meta, *http.Response, error) { //nolint:dupl uri := "/v2/ssh-keys" req, err := s.client.NewRequest(ctx, http.MethodGet, uri, nil) diff --git a/startup_script.go b/startup_script.go index 2d3c497..cacc70b 100644 --- a/startup_script.go +++ b/startup_script.go @@ -12,7 +12,7 @@ const scriptPath = "/v2/startup-scripts" // StartupScriptService is the interface to interact with the startup script endpoints on the Vultr API // Link : https://www.vultr.com/api/#tag/startup -type StartupScriptService interface { +type StartupScriptService interface { //nolint:dupl Create(ctx context.Context, req *StartupScriptReq) (*StartupScript, *http.Response, error) Get(ctx context.Context, scriptID string) (*StartupScript, *http.Response, error) Update(ctx context.Context, scriptID string, scriptReq *StartupScriptReq) error @@ -114,7 +114,7 @@ func (s *StartupScriptServiceHandler) Delete(ctx context.Context, scriptID strin } // List all the startup scripts associated with your Vultr account -func (s *StartupScriptServiceHandler) List(ctx context.Context, options *ListOptions) ([]StartupScript, *Meta, *http.Response, error) { +func (s *StartupScriptServiceHandler) List(ctx context.Context, options *ListOptions) ([]StartupScript, *Meta, *http.Response, error) { //nolint:dupl,lll req, err := s.client.NewRequest(ctx, http.MethodGet, scriptPath, nil) if err != nil { return nil, nil, nil, err diff --git a/user.go b/user.go index 2e162b8..bfd9593 100644 --- a/user.go +++ b/user.go @@ -12,7 +12,7 @@ const path = "/v2/users" // UserService is the interface to interact with the user management endpoints on the Vultr API // Link : https://www.vultr.com/api/#tag/users -type UserService interface { +type UserService interface { //nolint:dupl Create(ctx context.Context, userCreate *UserReq) (*User, *http.Response, error) Get(ctx context.Context, userID string) (*User, *http.Response, error) Update(ctx context.Context, userID string, userReq *UserReq) error @@ -115,7 +115,7 @@ func (u *UserServiceHandler) Delete(ctx context.Context, userID string) error { } // List will list all the users associated with your Vultr account -func (u *UserServiceHandler) List(ctx context.Context, options *ListOptions) ([]User, *Meta, *http.Response, error) { +func (u *UserServiceHandler) List(ctx context.Context, options *ListOptions) ([]User, *Meta, *http.Response, error) { //nolint:dupl req, err := u.client.NewRequest(ctx, http.MethodGet, path, nil) if err != nil { return nil, nil, nil, err diff --git a/vpc.go b/vpc.go index 7117cfb..1de69f8 100644 --- a/vpc.go +++ b/vpc.go @@ -1,4 +1,4 @@ -package govultr +package govultr //nolint:dupl import ( "context" @@ -86,7 +86,7 @@ func (n *VPCServiceHandler) Get(ctx context.Context, vpcID string) (*VPC, *http. } // Update updates a VPC -func (n *VPCServiceHandler) Update(ctx context.Context, vpcID string, description string) error { +func (n *VPCServiceHandler) Update(ctx context.Context, vpcID, description string) error { uri := fmt.Sprintf("%s/%s", vpcPath, vpcID) vpcReq := RequestBody{"description": description} @@ -111,7 +111,7 @@ func (n *VPCServiceHandler) Delete(ctx context.Context, vpcID string) error { } // List lists all VPCs on the current account -func (n *VPCServiceHandler) List(ctx context.Context, options *ListOptions) ([]VPC, *Meta, *http.Response, error) { +func (n *VPCServiceHandler) List(ctx context.Context, options *ListOptions) ([]VPC, *Meta, *http.Response, error) { //nolint:dupl req, err := n.client.NewRequest(ctx, http.MethodGet, vpcPath, nil) if err != nil { return nil, nil, nil, err