diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 000000000..297bb973c --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,20 @@ +name: golangci-lint +on: + merge_group: + pull_request: +permissions: + contents: read + checks: write + pull-requests: read +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: latest + args: --timeout 5m diff --git a/.golangci.yml b/.golangci.yml index ce39dc4c1..9b00ff7ac 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,28 +8,22 @@ linters: # Run golangci-lint linters to see enable: - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - - goconst - - goimports - - golint - - misspell - - stylecheck - - unconvert - - unparam - - whitespace - - gosec - # - wsl Could be interesting but need a lot of changes + - asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false] + - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false] + - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false] + - decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false] + - dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false] + - dupword # checks for duplicate words in the source code [fast: true, auto-fix: true] + - gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false] + - gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true] + - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true] + - goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true] + - whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true] issues: + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-rules: - path: _test\.go linters: diff --git a/api/applesilicon/v1alpha1/apple_silicon_utils.go b/api/applesilicon/v1alpha1/apple_silicon_utils.go index f76ad4a7a..ccc3a55a9 100644 --- a/api/applesilicon/v1alpha1/apple_silicon_utils.go +++ b/api/applesilicon/v1alpha1/apple_silicon_utils.go @@ -44,7 +44,6 @@ func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption ServerID: req.ServerID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/block/v1alpha1/snapshot_utils.go b/api/block/v1alpha1/snapshot_utils.go index d16f6114f..8d7c58aab 100644 --- a/api/block/v1alpha1/snapshot_utils.go +++ b/api/block/v1alpha1/snapshot_utils.go @@ -41,7 +41,6 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp SnapshotID: req.SnapshotID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/block/v1alpha1/volume_utils.go b/api/block/v1alpha1/volume_utils.go index 229b4111d..c32937f8a 100644 --- a/api/block/v1alpha1/volume_utils.go +++ b/api/block/v1alpha1/volume_utils.go @@ -56,7 +56,6 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest, opts ...scw.RequestOption VolumeID: req.VolumeID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/cockpit/v1beta1/cockpit_utils.go b/api/cockpit/v1beta1/cockpit_utils.go index 640097d2d..88b804ec5 100644 --- a/api/cockpit/v1beta1/cockpit_utils.go +++ b/api/cockpit/v1beta1/cockpit_utils.go @@ -54,7 +54,6 @@ func (s *API) WaitForCockpit( Timeout: timeout, IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) - if err != nil { return nil, errors.Wrap(err, "waiting for Cockpit failed") } diff --git a/api/dedibox/v1/dedibox_utils.go b/api/dedibox/v1/dedibox_utils.go index 16d8e4fa2..20e2c16c4 100644 --- a/api/dedibox/v1/dedibox_utils.go +++ b/api/dedibox/v1/dedibox_utils.go @@ -1,10 +1,11 @@ package dedibox import ( + "time" + "github.com/scaleway/scaleway-sdk-go/internal/async" "github.com/scaleway/scaleway-sdk-go/internal/errors" "github.com/scaleway/scaleway-sdk-go/scw" - "time" ) const ( diff --git a/api/documentdb/v1beta1/documentdb_utils.go b/api/documentdb/v1beta1/documentdb_utils.go index 72c0052f4..a4681d8c8 100644 --- a/api/documentdb/v1beta1/documentdb_utils.go +++ b/api/documentdb/v1beta1/documentdb_utils.go @@ -45,7 +45,6 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest, opts ...scw.RequestOp InstanceID: req.InstanceID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -91,7 +90,6 @@ func (s *API) WaitForInstanceLog(req *WaitForInstanceLogRequest, opts ...scw.Req res, err := s.GetInstanceLog(&GetInstanceLogRequest{ Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -139,7 +137,6 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req ReadReplicaID: req.ReadReplicaID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/domain/v2beta1/domain_utils.go b/api/domain/v2beta1/domain_utils.go index 0987dc39f..1d71e9d63 100644 --- a/api/domain/v2beta1/domain_utils.go +++ b/api/domain/v2beta1/domain_utils.go @@ -34,7 +34,6 @@ func (s *API) WaitForDNSZone( req *WaitForDNSZoneRequest, opts ...scw.RequestOption, ) (*DNSZone, error) { - timeout := defaultTimeout if req.Timeout != nil { timeout = *req.Timeout @@ -62,7 +61,6 @@ func (s *API) WaitForDNSZone( // listing dns zones and take the first one DNSZones, err := s.ListDNSZones(listReq, opts...) - if err != nil { return nil, false, err } @@ -80,7 +78,6 @@ func (s *API) WaitForDNSZone( Timeout: timeout, IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) - if err != nil { return nil, errors.Wrap(err, "waiting for DNS failed") } @@ -118,7 +115,6 @@ func (s *API) WaitForDNSRecordExist( Type: req.RecordType, DNSZone: req.DNSZone, }, opts...) - if err != nil { return nil, false, err } @@ -134,7 +130,6 @@ func (s *API) WaitForDNSRecordExist( Timeout: timeout, IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) - if err != nil { return nil, errors.Wrap(err, "check for DNS Record exist failed") } diff --git a/api/inference/v1beta1/inference_utils.go b/api/inference/v1beta1/inference_utils.go index 55ed36b3c..26255b27b 100644 --- a/api/inference/v1beta1/inference_utils.go +++ b/api/inference/v1beta1/inference_utils.go @@ -1,10 +1,11 @@ package inference import ( + "time" + "github.com/scaleway/scaleway-sdk-go/internal/async" "github.com/scaleway/scaleway-sdk-go/internal/errors" "github.com/scaleway/scaleway-sdk-go/scw" - "time" ) const ( diff --git a/api/instance/v1/image_utils.go b/api/instance/v1/image_utils.go index 99538fdff..343d92d97 100644 --- a/api/instance/v1/image_utils.go +++ b/api/instance/v1/image_utils.go @@ -38,7 +38,6 @@ func (s *API) WaitForImage(req *WaitForImageRequest, opts ...scw.RequestOption) ImageID: req.ImageID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/instance/v1/instance_metadata_sdk.go b/api/instance/v1/instance_metadata_sdk.go index 6bf35d64b..7fe912bb7 100644 --- a/api/instance/v1/instance_metadata_sdk.go +++ b/api/instance/v1/instance_metadata_sdk.go @@ -13,12 +13,12 @@ import ( "github.com/scaleway/scaleway-sdk-go/internal/errors" ) -var ( - metadataRetryBindPort = 200 -) +var metadataRetryBindPort = 200 -const metadataAPIv4 = "http://169.254.42.42" -const metadataAPIv6 = "http://[fd00:42::42]" +const ( + metadataAPIv4 = "http://169.254.42.42" + metadataAPIv6 = "http://[fd00:42::42]" +) // MetadataAPI metadata API type MetadataAPI struct { @@ -82,7 +82,7 @@ type Metadata struct { Organization string `json:"organization,omitempty"` Project string `json:"project,omitempty"` CommercialType string `json:"commercial_type,omitempty"` - //PublicIP IPv4 only + // PublicIP IPv4 only PublicIP struct { ID string `json:"id"` Address string `json:"address"` diff --git a/api/instance/v1/instance_sdk_server_test.go b/api/instance/v1/instance_sdk_server_test.go index ba3ebb7b8..e8e1cf4e8 100644 --- a/api/instance/v1/instance_sdk_server_test.go +++ b/api/instance/v1/instance_sdk_server_test.go @@ -153,9 +153,7 @@ func TestCreateServerWithIncorrectBody(t *testing.T) { instanceAPI := NewAPI(client) - var ( - zone = scw.ZoneFrPar1 - ) + zone := scw.ZoneFrPar1 // Create server _, err = instanceAPI.CreateServer(&CreateServerRequest{ diff --git a/api/instance/v1/instance_utils.go b/api/instance/v1/instance_utils.go index 75d891945..501f85979 100644 --- a/api/instance/v1/instance_utils.go +++ b/api/instance/v1/instance_utils.go @@ -7,14 +7,11 @@ import ( "time" "github.com/scaleway/scaleway-sdk-go/internal/async" - "github.com/scaleway/scaleway-sdk-go/internal/errors" "github.com/scaleway/scaleway-sdk-go/scw" ) -var ( - resourceLock sync.Map -) +var resourceLock sync.Map // lockResource locks a resource from a specific resourceID func lockResource(resourceID string) *sync.Mutex { @@ -315,7 +312,6 @@ func (s *API) WaitForPrivateNIC(req *WaitForPrivateNICRequest, opts ...scw.Reque Zone: req.Zone, PrivateNicID: req.PrivateNicID, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/instance/v1/server_utils.go b/api/instance/v1/server_utils.go index 4000a579c..a81a441c9 100644 --- a/api/instance/v1/server_utils.go +++ b/api/instance/v1/server_utils.go @@ -79,7 +79,6 @@ func (s *API) WaitForServer(req *WaitForServerRequest, opts ...scw.RequestOption ServerID: req.ServerID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } @@ -168,7 +167,6 @@ func (s *API) GetServerType(req *GetServerTypeRequest) (*ServerType, error) { res, err := s.ListServersTypes(&ListServersTypesRequest{ Zone: req.Zone, }, scw.WithAllPages()) - if err != nil { return nil, err } diff --git a/api/instance/v1/snapshot_utils.go b/api/instance/v1/snapshot_utils.go index 6efc419d3..b254bc432 100644 --- a/api/instance/v1/snapshot_utils.go +++ b/api/instance/v1/snapshot_utils.go @@ -38,7 +38,6 @@ func (s *API) WaitForSnapshot(req *WaitForSnapshotRequest, opts ...scw.RequestOp SnapshotID: req.SnapshotID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/instance/v1/snapshot_utils_test.go b/api/instance/v1/snapshot_utils_test.go index 88b85eddd..7793be66f 100644 --- a/api/instance/v1/snapshot_utils_test.go +++ b/api/instance/v1/snapshot_utils_test.go @@ -75,9 +75,7 @@ func TestAPI_UpdateSnapshot(t *testing.T) { instanceAPI := NewAPI(client) - var ( - volumeSize = 1 * scw.GB - ) + volumeSize := 1 * scw.GB createVolume, err := instanceAPI.CreateVolume(&CreateVolumeRequest{ Name: "volume_name", diff --git a/api/instance/v1/volume_utils.go b/api/instance/v1/volume_utils.go index 33004acf2..1a6d998d8 100644 --- a/api/instance/v1/volume_utils.go +++ b/api/instance/v1/volume_utils.go @@ -40,7 +40,6 @@ func (s *API) WaitForVolume(req *WaitForVolumeRequest, opts ...scw.RequestOption VolumeID: req.VolumeID, Zone: req.Zone, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/jobs/v1alpha1/custom_job_run.go b/api/jobs/v1alpha1/custom_job_run.go index 2f6428326..ef415e11c 100644 --- a/api/jobs/v1alpha1/custom_job_run.go +++ b/api/jobs/v1alpha1/custom_job_run.go @@ -44,7 +44,6 @@ func (s *API) WaitForJobRun(req *WaitForJobRunRequest, opts ...scw.RequestOption JobRunID: req.JobRunID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/k8s/v1/k8s_helpers.go b/api/k8s/v1/k8s_helpers.go index ed6cf46b4..43e431dfd 100644 --- a/api/k8s/v1/k8s_helpers.go +++ b/api/k8s/v1/k8s_helpers.go @@ -95,7 +95,6 @@ func (s *API) WaitForPool(req *WaitForPoolRequest, opts ...scw.RequestOption) (* PoolID: req.PoolID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -143,7 +142,6 @@ func (s *API) WaitForNode(req *WaitForNodeRequest, opts ...scw.RequestOption) (* NodeID: req.NodeID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/lb/v1/lb_utils.go b/api/lb/v1/lb_utils.go index b0a5f1182..416850090 100644 --- a/api/lb/v1/lb_utils.go +++ b/api/lb/v1/lb_utils.go @@ -71,7 +71,6 @@ func waitForLb(timeout *time.Duration, retryInterval *time.Duration, getLB func( lb, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := getLB() - if err != nil { return nil, false, err } @@ -189,7 +188,7 @@ func waitForPNLb(timeout *time.Duration, retryInterval *time.Duration, getPNs fu if err != nil { return nil, false, err } - //wait at the first not terminal state + // wait at the first not terminal state _, isTerminal := terminalStatus[pn.Status] if !isTerminal { return pns, isTerminal, nil @@ -259,7 +258,6 @@ func waitForLBCertificate(timeout *time.Duration, retryInterval *time.Duration, crt, err := async.WaitSync(&async.WaitSyncConfig{ Get: func() (interface{}, bool, error) { res, err := getCertificate() - if err != nil { return nil, false, err } diff --git a/api/marketplace/v2/marketplace_utils_test.go b/api/marketplace/v2/marketplace_utils_test.go index 48d5ed29b..9ffd6ee78 100644 --- a/api/marketplace/v2/marketplace_utils_test.go +++ b/api/marketplace/v2/marketplace_utils_test.go @@ -55,6 +55,6 @@ func TestGetImageByLabel(t *testing.T) { ImageLabel: "foo-bar-image", }) testhelpers.Assert(t, err != nil, "Should have error") - //testhelpers.Equals(t, "scaleway-sdk-go: couldn't find a matching image for the given label (foo-bar-image)", err.Error()) + // testhelpers.Equals(t, "scaleway-sdk-go: couldn't find a matching image for the given label (foo-bar-image)", err.Error()) }) } diff --git a/api/rdb/v1/rdb_utils.go b/api/rdb/v1/rdb_utils.go index b3c678915..2587005e6 100644 --- a/api/rdb/v1/rdb_utils.go +++ b/api/rdb/v1/rdb_utils.go @@ -45,7 +45,6 @@ func (s *API) WaitForInstance(req *WaitForInstanceRequest, opts ...scw.RequestOp InstanceID: req.InstanceID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -92,7 +91,6 @@ func (s *API) WaitForDatabaseBackup(req *WaitForDatabaseBackupRequest, opts ...s DatabaseBackupID: req.DatabaseBackupID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -139,7 +137,6 @@ func (s *API) WaitForInstanceLog(req *WaitForInstanceLogRequest, opts ...scw.Req Region: req.Region, InstanceLogID: req.InstanceLogID, }, opts...) - if err != nil { return nil, false, err } @@ -187,7 +184,6 @@ func (s *API) WaitForReadReplica(req *WaitForReadReplicaRequest, opts ...scw.Req ReadReplicaID: req.ReadReplicaID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } diff --git a/api/serverless_sqldb/v1alpha1/serverless_sqldb_utils.go b/api/serverless_sqldb/v1alpha1/serverless_sqldb_utils.go index 1149e6d53..7d901f309 100644 --- a/api/serverless_sqldb/v1alpha1/serverless_sqldb_utils.go +++ b/api/serverless_sqldb/v1alpha1/serverless_sqldb_utils.go @@ -45,7 +45,6 @@ func (s *API) WaitForDatabase(req *WaitForDatabaseRequest, opts ...scw.RequestOp DatabaseID: req.DatabaseID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -94,7 +93,6 @@ func (s *API) WaitForDatabaseBackup(req *WaitForDatabaseBackupRequest, opts ...s BackupID: req.BackupID, Region: req.Region, }, opts...) - if err != nil { return nil, false, err } @@ -106,7 +104,7 @@ func (s *API) WaitForDatabaseBackup(req *WaitForDatabaseBackupRequest, opts ...s IntervalStrategy: async.LinearIntervalStrategy(retryInterval), }) if err != nil { - return nil, errors.Wrap(err, "waiting for backup backup failed") + return nil, errors.Wrap(err, "waiting for database backup failed") } return backup.(*DatabaseBackup), nil } diff --git a/doc.go b/doc.go index af3079ea1..f409f2f51 100644 --- a/doc.go +++ b/doc.go @@ -3,5 +3,4 @@ // In order to use the available APIs, create a `Client`. Once created, it can be used to instantiate an API. // To use the `instance` API, for example, instantiate it (with the client object) `instance.NewApi(client)`. // On this instance API, all the available API functions can be called. -// package scalewaysdkgo diff --git a/example_test.go b/example_test.go index 0c0b06879..ffda95a3d 100644 --- a/example_test.go +++ b/example_test.go @@ -200,7 +200,6 @@ func Example_createLoadBalancer() { OrganizationID: scw.StringPtr("000a115d-2852-4b0a-9ce8-47f1134ba95a"), Region: scw.RegionFrPar, }) - if err != nil { // handle error } diff --git a/internal/async/wait.go b/internal/async/wait.go index 7e0d2158f..01e920a72 100644 --- a/internal/async/wait.go +++ b/internal/async/wait.go @@ -56,7 +56,6 @@ func WaitSync(config *WaitSyncConfig) (terminalValue interface{}, err error) { for { // get the payload value, stopCondition, err := config.Get() - // send the payload if err != nil { resultErr <- err diff --git a/internal/auth/no_auth.go b/internal/auth/no_auth.go index 2181c57c2..5a8686945 100644 --- a/internal/auth/no_auth.go +++ b/internal/auth/no_auth.go @@ -2,8 +2,7 @@ package auth import "net/http" -type NoAuth struct { -} +type NoAuth struct{} // NewNoAuth return an auth with no authentication method func NewNoAuth() *NoAuth { diff --git a/internal/e2e/human_test.go b/internal/e2e/human_test.go index a4ef6c7c9..fbac36073 100644 --- a/internal/e2e/human_test.go +++ b/internal/e2e/human_test.go @@ -8,9 +8,7 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" ) -var ( - defaultOrganizationID = "6170692e-7363-616c-6577-61792e636f6d" // hint: | xxd -ps -r -) +var defaultOrganizationID = "6170692e-7363-616c-6577-61792e636f6d" // hint: | xxd -ps -r func newE2EClient(withAuthInClient bool) (*test.API, string, string, error) { client, err := scw.NewClient( diff --git a/logger/default_logger.go b/logger/default_logger.go index bdf1de8d0..0c2d64c72 100644 --- a/logger/default_logger.go +++ b/logger/default_logger.go @@ -9,8 +9,10 @@ import ( "strconv" ) -var DefaultLogger = newLogger(os.Stderr, LogLevelWarning) -var logger Logger = DefaultLogger +var ( + DefaultLogger = newLogger(os.Stderr, LogLevelWarning) + logger Logger = DefaultLogger +) // loggerT is the default logger used by scaleway-sdk-go. type loggerT struct { @@ -27,30 +29,35 @@ func (g *loggerT) Init(w io.Writer, level LogLevel) { // Debugf logs to the DEBUG log. Arguments are handled in the manner of fmt.Printf. func Debugf(format string, args ...interface{}) { logger.Debugf(format, args...) } + func (g *loggerT) Debugf(format string, args ...interface{}) { g.m[LogLevelDebug].Printf(format, args...) } // Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf. func Infof(format string, args ...interface{}) { logger.Infof(format, args...) } + func (g *loggerT) Infof(format string, args ...interface{}) { g.m[LogLevelInfo].Printf(format, args...) } // Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf. func Warningf(format string, args ...interface{}) { logger.Warningf(format, args...) } + func (g *loggerT) Warningf(format string, args ...interface{}) { g.m[LogLevelWarning].Printf(format, args...) } // Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf. func Errorf(format string, args ...interface{}) { logger.Errorf(format, args...) } + func (g *loggerT) Errorf(format string, args ...interface{}) { g.m[LogLevelError].Printf(format, args...) } // ShouldLog reports whether verbosity level l is at least the requested verbose level. func ShouldLog(level LogLevel) bool { return logger.ShouldLog(level) } + func (g *loggerT) ShouldLog(level LogLevel) bool { return level >= g.v } diff --git a/namegenerator/name_generator.go b/namegenerator/name_generator.go index 11fda4532..213c34a21 100644 --- a/namegenerator/name_generator.go +++ b/namegenerator/name_generator.go @@ -397,7 +397,7 @@ var ( // Jane Goodall - British primatologist, ethologist, and anthropologist who is considered to be the world's foremost expert on chimpanzees - https://en.wikipedia.org/wiki/Jane_Goodall "goodall", - // Stephen Jay Gould was was an American paleontologist, evolutionary biologist, and historian of science. He is most famous for the theory of punctuated equilibrium - https://en.wikipedia.org/wiki/Stephen_Jay_Gould + // Stephen Jay Gould was an American paleontologist, evolutionary biologist, and historian of science. He is most famous for the theory of punctuated equilibrium - https://en.wikipedia.org/wiki/Stephen_Jay_Gould "gould", // Carolyn Widney Greider - American molecular biologist and joint winner of the 2009 Nobel Prize for Physiology or Medicine for the discovery of telomerase. https://en.wikipedia.org/wiki/Carol_W._Greider diff --git a/scw/client.go b/scw/client.go index c6a288d1d..17bebd9aa 100644 --- a/scw/client.go +++ b/scw/client.go @@ -189,7 +189,6 @@ func (c *Client) Do(req *ScalewayRequest, res interface{}, opts ...RequestOption // do performs a single HTTP request based on the ScalewayRequest object. func (c *Client) do(req *ScalewayRequest, res interface{}) (sdkErr error) { - if req == nil { return errors.New("request must be non-nil") } diff --git a/scw/client_test.go b/scw/client_test.go index eaafdab89..d202aeede 100644 --- a/scw/client_test.go +++ b/scw/client_test.go @@ -71,7 +71,6 @@ func TestNewClientMultipleClients(t *testing.T) { testhelpers.Assert(t, isLogger, "transport should be a request logger") _, isLogger = transport.rt.(*requestLoggerTransport) testhelpers.Assert(t, !isLogger, "nested transport should not be a request logger") - }) } diff --git a/scw/config.go b/scw/config.go index 0fbaef968..d979ea48c 100644 --- a/scw/config.go +++ b/scw/config.go @@ -9,16 +9,15 @@ import ( "strings" "text/template" - "gopkg.in/yaml.v2" - "github.com/scaleway/scaleway-sdk-go/internal/auth" "github.com/scaleway/scaleway-sdk-go/internal/errors" "github.com/scaleway/scaleway-sdk-go/logger" + "gopkg.in/yaml.v2" ) const ( documentationLink = "https://github.com/scaleway/scaleway-sdk-go/blob/master/scw/README.md" - defaultConfigPermission = 0600 + defaultConfigPermission = 0o600 // Reserved name for the default profile. DefaultProfileName = "default" @@ -299,7 +298,7 @@ func (c *Config) SaveTo(path string) error { } // STEP 2: create config path dir in cases it didn't exist before - err = os.MkdirAll(filepath.Dir(path), 0700) + err = os.MkdirAll(filepath.Dir(path), 0o700) if err != nil { return err } diff --git a/scw/config_test.go b/scw/config_test.go index f2997caeb..7bc1b13a2 100644 --- a/scw/config_test.go +++ b/scw/config_test.go @@ -448,7 +448,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) { } func TestConfigString(t *testing.T) { - var c = &Config{ + c := &Config{ Profile: Profile{ AccessKey: s(v2ValidAccessKey), SecretKey: s(v2ValidSecretKey), @@ -531,7 +531,7 @@ func setEnv(t *testing.T, env, files map[string]string, homeDir string) { for path, content := range files { targetPath := filepath.Join(homeDir, path) - testhelpers.AssertNoError(t, os.MkdirAll(filepath.Dir(targetPath), 0700)) + testhelpers.AssertNoError(t, os.MkdirAll(filepath.Dir(targetPath), 0o700)) testhelpers.AssertNoError(t, ioutil.WriteFile(targetPath, []byte(content), defaultConfigPermission)) } } @@ -662,7 +662,8 @@ func TestConfig_ConfigFile(t *testing.T) { config: &Config{ Profile: Profile{ AccessKey: s(v2ValidAccessKey), - }}, + }, + }, result: `# Scaleway configuration file # https://github.com/scaleway/scaleway-sdk-go/tree/master/scw#scaleway-config diff --git a/scw/custom_types_test.go b/scw/custom_types_test.go index c499277f9..49512d228 100644 --- a/scw/custom_types_test.go +++ b/scw/custom_types_test.go @@ -200,11 +200,11 @@ func TestTimeSeries_MarshallJSON(t *testing.T) { Name: "cpu_usage", Points: []*TimeSeriesPoint{ { - Timestamp: time.Date(2019, time.August, 8, 15, 00, 00, 0, time.UTC), + Timestamp: time.Date(2019, time.August, 8, 15, 0, 0, 0, time.UTC), Value: 0.2, }, { - Timestamp: time.Date(2019, time.August, 8, 15, 01, 00, 0, time.UTC), + Timestamp: time.Date(2019, time.August, 8, 15, 1, 0, 0, time.UTC), Value: 10.6, }, }, @@ -253,11 +253,11 @@ func TestTimeSeries_UnmarshalJSON(t *testing.T) { Name: "cpu_usage", Points: []*TimeSeriesPoint{ { - Timestamp: time.Date(2019, time.August, 8, 15, 00, 00, 0, time.UTC), + Timestamp: time.Date(2019, time.August, 8, 15, 0o0, 0o0, 0, time.UTC), Value: 0.2, }, { - Timestamp: time.Date(2019, time.August, 8, 15, 01, 00, 0, time.UTC), + Timestamp: time.Date(2019, time.August, 8, 15, 0o1, 0o0, 0, time.UTC), Value: 10.6, }, }, diff --git a/scw/env.go b/scw/env.go index d6232ba2e..ae42e3e37 100644 --- a/scw/env.go +++ b/scw/env.go @@ -35,20 +35,20 @@ const ( cliSecretKeyEnv = "SCW_TOKEN" // TBD - //cliVerboseEnv = "SCW_VERBOSE_API" - //cliDebugEnv = "DEBUG" - //cliNoCheckVersionEnv = "SCW_NOCHECKVERSION" - //cliTestWithRealAPIEnv = "TEST_WITH_REAL_API" - //cliSecureExecEnv = "SCW_SECURE_EXEC" - //cliGatewayEnv = "SCW_GATEWAY" - //cliSensitiveEnv = "SCW_SENSITIVE" - //cliAccountAPIEnv = "SCW_ACCOUNT_API" - //cliMetadataAPIEnv = "SCW_METADATA_API" - //cliMarketPlaceAPIEnv = "SCW_MARKETPLACE_API" - //cliComputePar1APIEnv = "SCW_COMPUTE_PAR1_API" - //cliComputeAms1APIEnv = "SCW_COMPUTE_AMS1_API" - //cliCommercialTypeEnv = "SCW_COMMERCIAL_TYPE" - //cliTargetArchEnv = "SCW_TARGET_ARCH" + // cliVerboseEnv = "SCW_VERBOSE_API" + // cliDebugEnv = "DEBUG" + // cliNoCheckVersionEnv = "SCW_NOCHECKVERSION" + // cliTestWithRealAPIEnv = "TEST_WITH_REAL_API" + // cliSecureExecEnv = "SCW_SECURE_EXEC" + // cliGatewayEnv = "SCW_GATEWAY" + // cliSensitiveEnv = "SCW_SENSITIVE" + // cliAccountAPIEnv = "SCW_ACCOUNT_API" + // cliMetadataAPIEnv = "SCW_METADATA_API" + // cliMarketPlaceAPIEnv = "SCW_MARKETPLACE_API" + // cliComputePar1APIEnv = "SCW_COMPUTE_PAR1_API" + // cliComputeAms1APIEnv = "SCW_COMPUTE_AMS1_API" + // cliCommercialTypeEnv = "SCW_COMMERCIAL_TYPE" + // cliTargetArchEnv = "SCW_TARGET_ARCH" ) const ( diff --git a/scw/errors.go b/scw/errors.go index 3563b0de9..fe6080d9e 100644 --- a/scw/errors.go +++ b/scw/errors.go @@ -59,6 +59,7 @@ func (e *ResponseError) UnmarshalJSON(b []byte) error { // IsScwSdkError implement SdkError interface func (e *ResponseError) IsScwSdkError() {} + func (e *ResponseError) Error() string { s := fmt.Sprintf("scaleway-sdk-go: http error %s", e.Status) @@ -76,6 +77,7 @@ func (e *ResponseError) Error() string { return s } + func (e *ResponseError) GetRawBody() json.RawMessage { return e.RawBody } @@ -214,6 +216,7 @@ type InvalidArgumentsError struct { // IsScwSdkError implements the SdkError interface func (e *InvalidArgumentsError) IsScwSdkError() {} + func (e *InvalidArgumentsError) Error() string { invalidArgs := make([]string, len(e.Details)) for i, d := range e.Details { @@ -235,6 +238,7 @@ func (e *InvalidArgumentsError) Error() string { return "scaleway-sdk-go: invalid argument(s): " + strings.Join(invalidArgs, "; ") } + func (e *InvalidArgumentsError) GetRawBody() json.RawMessage { return e.RawBody } @@ -344,6 +348,7 @@ type QuotasExceededError struct { // IsScwSdkError implements the SdkError interface func (e *QuotasExceededError) IsScwSdkError() {} + func (e *QuotasExceededError) Error() string { invalidArgs := make([]string, len(e.Details)) for i, d := range e.Details { @@ -352,6 +357,7 @@ func (e *QuotasExceededError) Error() string { return "scaleway-sdk-go: quota exceeded(s): " + strings.Join(invalidArgs, "; ") } + func (e *QuotasExceededError) GetRawBody() json.RawMessage { return e.RawBody } @@ -367,6 +373,7 @@ type PermissionsDeniedError struct { // IsScwSdkError implements the SdkError interface func (e *PermissionsDeniedError) IsScwSdkError() {} + func (e *PermissionsDeniedError) Error() string { invalidArgs := make([]string, len(e.Details)) for i, d := range e.Details { @@ -375,6 +382,7 @@ func (e *PermissionsDeniedError) Error() string { return "scaleway-sdk-go: insufficient permissions: " + strings.Join(invalidArgs, "; ") } + func (e *PermissionsDeniedError) GetRawBody() json.RawMessage { return e.RawBody } @@ -389,9 +397,11 @@ type TransientStateError struct { // IsScwSdkError implements the SdkError interface func (e *TransientStateError) IsScwSdkError() {} + func (e *TransientStateError) Error() string { return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is in a transient state: %s", e.Resource, e.ResourceID, e.CurrentState) } + func (e *TransientStateError) GetRawBody() json.RawMessage { return e.RawBody } @@ -405,9 +415,11 @@ type ResourceNotFoundError struct { // IsScwSdkError implements the SdkError interface func (e *ResourceNotFoundError) IsScwSdkError() {} + func (e *ResourceNotFoundError) Error() string { return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is not found", e.Resource, e.ResourceID) } + func (e *ResourceNotFoundError) GetRawBody() json.RawMessage { return e.RawBody } @@ -421,9 +433,11 @@ type ResourceLockedError struct { // IsScwSdkError implements the SdkError interface func (e *ResourceLockedError) IsScwSdkError() {} + func (e *ResourceLockedError) Error() string { return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is locked", e.Resource, e.ResourceID) } + func (e *ResourceLockedError) GetRawBody() json.RawMessage { return e.RawBody } @@ -436,9 +450,11 @@ type OutOfStockError struct { // IsScwSdkError implements the SdkError interface func (e *OutOfStockError) IsScwSdkError() {} + func (e *OutOfStockError) Error() string { return fmt.Sprintf("scaleway-sdk-go: resource %s is out of stock", e.Resource) } + func (e *OutOfStockError) GetRawBody() json.RawMessage { return e.RawBody } @@ -454,6 +470,7 @@ func NewInvalidClientOptionError(format string, a ...interface{}) *InvalidClient // IsScwSdkError implements the SdkError interface func (e InvalidClientOptionError) IsScwSdkError() {} + func (e InvalidClientOptionError) Error() string { return fmt.Sprintf("scaleway-sdk-go: %s", e.errorType) } @@ -469,6 +486,7 @@ func configFileNotFound(path string) *ConfigFileNotFoundError { // ConfigFileNotFoundError implements the SdkError interface func (e ConfigFileNotFoundError) IsScwSdkError() {} + func (e ConfigFileNotFoundError) Error() string { return fmt.Sprintf("scaleway-sdk-go: cannot read config file %s: no such file or directory", e.path) } diff --git a/scw/errors_test.go b/scw/errors_test.go index 6e218f039..6bdec0736 100644 --- a/scw/errors_test.go +++ b/scw/errors_test.go @@ -194,7 +194,7 @@ func TestHasResponseErrorWithValidError(t *testing.T) { Status: errorStatus, StatusCode: errorStatusCode, Header: map[string][]string{ - "Content-Type": []string{"application/json"}, + "Content-Type": {"application/json"}, }, Body: ioutil.NopCloser(bytes.NewReader(bodyBytes)), } diff --git a/scw/locality.go b/scw/locality.go index 55e0a1543..ffe84381b 100644 --- a/scw/locality.go +++ b/scw/locality.go @@ -37,20 +37,18 @@ const ( ZonePlWaw3 = Zone("pl-waw-3") ) -var ( - // AllZones is an array that list all zones - AllZones = []Zone{ - ZoneFrPar1, - ZoneFrPar2, - ZoneFrPar3, - ZoneNlAms1, - ZoneNlAms2, - ZoneNlAms3, - ZonePlWaw1, - ZonePlWaw2, - ZonePlWaw3, - } -) +// AllZones is an array that list all zones +var AllZones = []Zone{ + ZoneFrPar1, + ZoneFrPar2, + ZoneFrPar3, + ZoneNlAms1, + ZoneNlAms2, + ZoneNlAms3, + ZonePlWaw1, + ZonePlWaw2, + ZonePlWaw3, +} // Exists checks whether a zone exists func (zone Zone) Exists() bool { @@ -90,14 +88,12 @@ const ( RegionPlWaw = Region("pl-waw") ) -var ( - // AllRegions is an array that list all regions - AllRegions = []Region{ - RegionFrPar, - RegionNlAms, - RegionPlWaw, - } -) +// AllRegions is an array that list all regions +var AllRegions = []Region{ + RegionFrPar, + RegionNlAms, + RegionPlWaw, +} // Exists checks whether a region exists func (region Region) Exists() bool { diff --git a/scw/path.go b/scw/path.go index 7bc0a3c3c..71e153e0c 100644 --- a/scw/path.go +++ b/scw/path.go @@ -17,10 +17,8 @@ const ( defaultConfigFileName = "config.yaml" ) -var ( - // ErrNoHomeDir errors when no user directory is found - ErrNoHomeDir = errors.New("user home directory not found") -) +// ErrNoHomeDir errors when no user directory is found +var ErrNoHomeDir = errors.New("user home directory not found") // GetCacheDirectory returns the default cache directory. // Cache directory is based on the following priority order: diff --git a/scw/version.go b/scw/version.go index f8e357544..3018df484 100644 --- a/scw/version.go +++ b/scw/version.go @@ -7,8 +7,10 @@ import ( ) // TODO: versioning process -const defaultVersion = "v1.0.0-beta.7+dev" -const path = "github.com/scaleway/scaleway-sdk-go" +const ( + defaultVersion = "v1.0.0-beta.7+dev" + path = "github.com/scaleway/scaleway-sdk-go" +) var cachedVersion = (*string)(nil) diff --git a/strcase/number.go b/strcase/number.go index 5aeddf35e..361e76c67 100644 --- a/strcase/number.go +++ b/strcase/number.go @@ -4,8 +4,10 @@ import ( "regexp" ) -var numberSequence = regexp.MustCompile(`([a-zA-Z])(\d+)([a-zA-Z]?)`) -var numberReplacement = []byte(`$1 $2 $3`) +var ( + numberSequence = regexp.MustCompile(`([a-zA-Z])(\d+)([a-zA-Z]?)`) + numberReplacement = []byte(`$1 $2 $3`) +) func addWordBoundariesToNumbers(s string) string { b := []byte(s)