diff --git a/.golangci.yml b/.golangci.yml index 5dda89819..9278ec7ab 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,7 +12,7 @@ linters: - goimports - misspell - govet - - golint + - revive - ineffassign - gosimple - deadcode @@ -22,6 +22,7 @@ linters: - unused - structcheck - unconvert + - varcheck issues: exclude-use-default: false diff --git a/Makefile b/Makefile index cea8ad39b..7de90c218 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ checks: getdeps: @mkdir -p ${GOPATH}/bin - @which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0) + @echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.40.1 @which msgp 1>/dev/null || (echo "Installing msgp" && go install -v github.com/tinylib/msgp@v1.1.3) @which stringer 1>/dev/null || (echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer) diff --git a/cmd/config/config.go b/cmd/config/config.go index 33b20c6e3..c3d14c011 100644 --- a/cmd/config/config.go +++ b/cmd/config/config.go @@ -315,10 +315,7 @@ func (c Config) DelFrom(r io.Reader) error { return err } } - if err := scanner.Err(); err != nil { - return err - } - return nil + return scanner.Err() } // ReadConfig - read content from input and write into c. diff --git a/cmd/config/identity/ldap/config.go b/cmd/config/identity/ldap/config.go index f9237d615..f962cecec 100644 --- a/cmd/config/identity/ldap/config.go +++ b/cmd/config/identity/ldap/config.go @@ -189,7 +189,7 @@ func (l *Config) lookupBind(conn *ldap.Conn) error { err = conn.Bind(l.LookupBindDN, l.LookupBindPassword) } if ldap.IsErrorWithCode(err, 49) { - return fmt.Errorf("LDAP Lookup Bind user invalid credentials error: %v", err) + return fmt.Errorf("LDAP Lookup Bind user invalid credentials error: %w", err) } return err } @@ -214,7 +214,7 @@ func (l *Config) usernameFormatsBind(conn *ldap.Conn, username, password string) bindDistNames = append(bindDistNames, bindDN) successCount++ } else if !ldap.IsErrorWithCode(errs[i], 49) { - return "", fmt.Errorf("LDAP Bind request failed with unexpected error: %v", errs[i]) + return "", fmt.Errorf("LDAP Bind request failed with unexpected error: %w", errs[i]) } } if successCount == 0 { @@ -279,7 +279,7 @@ func (l *Config) searchForUserGroups(conn *ldap.Conn, username, bindDN string) ( var newGroups []string newGroups, err := getGroups(conn, searchRequest) if err != nil { - errRet := fmt.Errorf("Error finding groups of %s: %v", bindDN, err) + errRet := fmt.Errorf("Error finding groups of %s: %w", bindDN, err) return nil, errRet } @@ -341,14 +341,14 @@ func (l *Config) Bind(username, password string) (string, []string, error) { // Lookup user DN bindDN, err = l.lookupUserDN(conn, username) if err != nil { - errRet := fmt.Errorf("Unable to find user DN: %s", err) + errRet := fmt.Errorf("Unable to find user DN: %w", err) return "", nil, errRet } // Authenticate the user credentials. err = conn.Bind(bindDN, password) if err != nil { - errRet := fmt.Errorf("LDAP auth failed for DN %s: %v", bindDN, err) + errRet := fmt.Errorf("LDAP auth failed for DN %s: %w", bindDN, err) return "", nil, errRet } @@ -366,7 +366,7 @@ func (l *Config) Bind(username, password string) (string, []string, error) { // Bind to the successful bindDN again. err = conn.Bind(bindDN, password) if err != nil { - errRet := fmt.Errorf("LDAP conn failed though auth for DN %s succeeded: %v", bindDN, err) + errRet := fmt.Errorf("LDAP conn failed though auth for DN %s succeeded: %w", bindDN, err) return "", nil, errRet } } @@ -423,12 +423,12 @@ func (l Config) GetExpiryDuration() time.Duration { func (l Config) testConnection() error { conn, err := l.Connect() if err != nil { - return fmt.Errorf("Error creating connection to LDAP server: %v", err) + return fmt.Errorf("Error creating connection to LDAP server: %w", err) } defer conn.Close() if l.isUsingLookupBind { if err = l.lookupBind(conn); err != nil { - return fmt.Errorf("Error connecting as LDAP Lookup Bind user: %v", err) + return fmt.Errorf("Error connecting as LDAP Lookup Bind user: %w", err) } return nil } @@ -449,7 +449,7 @@ func (l Config) testConnection() error { } else if strings.HasPrefix(err.Error(), "All username formats failed due to invalid credentials: ") { return nil } - return fmt.Errorf("LDAP connection test error: %v", err) + return fmt.Errorf("LDAP connection test error: %w", err) } // Enabled returns if jwks is enabled. @@ -547,7 +547,7 @@ func Lookup(kvs config.KVS, rootCAs *x509.CertPool) (l Config, err error) { // Test connection to LDAP server. if err := l.testConnection(); err != nil { - return l, fmt.Errorf("Connection test for LDAP server failed: %v", err) + return l, fmt.Errorf("Connection test for LDAP server failed: %w", err) } // Group search params configuration diff --git a/cmd/config/notify/legacy.go b/cmd/config/notify/legacy.go index a686d8261..1e22e62be 100644 --- a/cmd/config/notify/legacy.go +++ b/cmd/config/notify/legacy.go @@ -27,7 +27,7 @@ import ( ) // SetNotifyKafka - helper for config migration from older config. -func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error { +func SetNotifyKafka(s config.Config, name string, cfg target.KafkaArgs) error { if !cfg.Enable { return nil } @@ -36,7 +36,7 @@ func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error { return err } - s[config.NotifyKafkaSubSys][kName] = config.KVS{ + s[config.NotifyKafkaSubSys][name] = config.KVS{ config.KV{ Key: config.Enable, Value: config.EnableOn, diff --git a/cmd/erasure-server-pool.go b/cmd/erasure-server-pool.go index 914812bd6..17c6b1828 100644 --- a/cmd/erasure-server-pool.go +++ b/cmd/erasure-server-pool.go @@ -622,7 +622,7 @@ func (z *erasureServerPools) GetObjectNInfo(ctx context.Context, bucket, object } wg.Wait() - var found int = -1 + var found = -1 for i, err := range errs { if err == nil { found = i @@ -683,7 +683,7 @@ func (z *erasureServerPools) GetObjectInfo(ctx context.Context, bucket, object s } wg.Wait() - var found int = -1 + var found = -1 for i, err := range errs { if err == nil { found = i diff --git a/cmd/format-disk-cache.go b/cmd/format-disk-cache.go index fb6c73c21..dda889101 100644 --- a/cmd/format-disk-cache.go +++ b/cmd/format-disk-cache.go @@ -495,8 +495,5 @@ func migrateCacheFormatJSON(cacheFormatPath string) error { formatV2.Version = formatMetaVersion1 formatV2.Cache = formatV1.Cache formatV2.Cache.Version = formatCacheVersionV2 - if err := jsonSave(f, formatV2); err != nil { - return err - } - return nil + return jsonSave(f, formatV2) } diff --git a/cmd/tier.go b/cmd/tier.go index ccacfd848..e4e88c8a2 100644 --- a/cmd/tier.go +++ b/cmd/tier.go @@ -49,7 +49,7 @@ const ( ) // tierConfigPath refers to remote tier config object name -var tierConfigPath string = path.Join(minioConfigPrefix, tierConfigFile) +var tierConfigPath = path.Join(minioConfigPrefix, tierConfigFile) // TierConfigMgr holds the collection of remote tiers configured in this deployment. type TierConfigMgr struct { diff --git a/pkg/bucket/replication/rule.go b/pkg/bucket/replication/rule.go index b272fdd48..bdc1adeed 100644 --- a/pkg/bucket/replication/rule.go +++ b/pkg/bucket/replication/rule.go @@ -140,10 +140,7 @@ func (r Rule) validateStatus() error { } func (r Rule) validateFilter() error { - if err := r.Filter.Validate(); err != nil { - return err - } - return nil + return r.Filter.Validate() } // Prefix - a rule can either have prefix under or under diff --git a/pkg/event/target/amqp.go b/pkg/event/target/amqp.go index c92970ca8..5667801c2 100644 --- a/pkg/event/target/amqp.go +++ b/pkg/event/target/amqp.go @@ -205,16 +205,12 @@ func (target *AMQPTarget) send(eventData event.Event, ch *amqp.Channel) error { return err } - if err := ch.Publish(target.args.Exchange, target.args.RoutingKey, target.args.Mandatory, + return ch.Publish(target.args.Exchange, target.args.RoutingKey, target.args.Mandatory, target.args.Immediate, amqp.Publishing{ ContentType: "application/json", DeliveryMode: target.args.DeliveryMode, Body: data, - }); err != nil { - return err - } - - return nil + }) } // Save - saves the events to the store which will be replayed when the amqp connection is active. diff --git a/pkg/s3select/csv/record.go b/pkg/s3select/csv/record.go index 07890192a..c24d8d3f2 100644 --- a/pkg/s3select/csv/record.go +++ b/pkg/s3select/csv/record.go @@ -103,11 +103,7 @@ func (r *Record) WriteCSV(writer io.Writer, opts sql.WriteCSVOpts) error { return err } w.Flush() - if err := w.Error(); err != nil { - return err - } - - return nil + return w.Error() } // WriteJSON - encodes to JSON data. diff --git a/pkg/s3select/json/record.go b/pkg/s3select/json/record.go index 31ce7e17a..470d38642 100644 --- a/pkg/s3select/json/record.go +++ b/pkg/s3select/json/record.go @@ -145,11 +145,7 @@ func (r *Record) WriteCSV(writer io.Writer, opts sql.WriteCSVOpts) error { return err } w.Flush() - if err := w.Error(); err != nil { - return err - } - - return nil + return w.Error() } // Raw - returns the underlying representation. diff --git a/pkg/s3select/simdj/record.go b/pkg/s3select/simdj/record.go index b68857bc9..bc30ecb9f 100644 --- a/pkg/s3select/simdj/record.go +++ b/pkg/s3select/simdj/record.go @@ -181,11 +181,7 @@ allElems: return err } w.Flush() - if err := w.Error(); err != nil { - return err - } - - return nil + return w.Error() } // Raw - returns the underlying representation.