fix: lint errors after upgrading golangci-lint (#12368)

This commit is contained in:
Harshavardhana 2021-05-25 14:17:33 -07:00 committed by GitHub
parent ed4941a5f3
commit 4fd1378242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 26 additions and 50 deletions

View File

@ -12,7 +12,7 @@ linters:
- goimports - goimports
- misspell - misspell
- govet - govet
- golint - revive
- ineffassign - ineffassign
- gosimple - gosimple
- deadcode - deadcode
@ -22,6 +22,7 @@ linters:
- unused - unused
- structcheck - structcheck
- unconvert - unconvert
- varcheck
issues: issues:
exclude-use-default: false exclude-use-default: false

View File

@ -16,7 +16,7 @@ checks:
getdeps: getdeps:
@mkdir -p ${GOPATH}/bin @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 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) @which stringer 1>/dev/null || (echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer)

View File

@ -315,10 +315,7 @@ func (c Config) DelFrom(r io.Reader) error {
return err return err
} }
} }
if err := scanner.Err(); err != nil { return scanner.Err()
return err
}
return nil
} }
// ReadConfig - read content from input and write into c. // ReadConfig - read content from input and write into c.

View File

@ -189,7 +189,7 @@ func (l *Config) lookupBind(conn *ldap.Conn) error {
err = conn.Bind(l.LookupBindDN, l.LookupBindPassword) err = conn.Bind(l.LookupBindDN, l.LookupBindPassword)
} }
if ldap.IsErrorWithCode(err, 49) { 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 return err
} }
@ -214,7 +214,7 @@ func (l *Config) usernameFormatsBind(conn *ldap.Conn, username, password string)
bindDistNames = append(bindDistNames, bindDN) bindDistNames = append(bindDistNames, bindDN)
successCount++ successCount++
} else if !ldap.IsErrorWithCode(errs[i], 49) { } 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 { if successCount == 0 {
@ -279,7 +279,7 @@ func (l *Config) searchForUserGroups(conn *ldap.Conn, username, bindDN string) (
var newGroups []string var newGroups []string
newGroups, err := getGroups(conn, searchRequest) newGroups, err := getGroups(conn, searchRequest)
if err != nil { 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 return nil, errRet
} }
@ -341,14 +341,14 @@ func (l *Config) Bind(username, password string) (string, []string, error) {
// Lookup user DN // Lookup user DN
bindDN, err = l.lookupUserDN(conn, username) bindDN, err = l.lookupUserDN(conn, username)
if err != nil { 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 return "", nil, errRet
} }
// Authenticate the user credentials. // Authenticate the user credentials.
err = conn.Bind(bindDN, password) err = conn.Bind(bindDN, password)
if err != nil { 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 return "", nil, errRet
} }
@ -366,7 +366,7 @@ func (l *Config) Bind(username, password string) (string, []string, error) {
// Bind to the successful bindDN again. // Bind to the successful bindDN again.
err = conn.Bind(bindDN, password) err = conn.Bind(bindDN, password)
if err != nil { 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 return "", nil, errRet
} }
} }
@ -423,12 +423,12 @@ func (l Config) GetExpiryDuration() time.Duration {
func (l Config) testConnection() error { func (l Config) testConnection() error {
conn, err := l.Connect() conn, err := l.Connect()
if err != nil { 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() defer conn.Close()
if l.isUsingLookupBind { if l.isUsingLookupBind {
if err = l.lookupBind(conn); err != nil { 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 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: ") { } else if strings.HasPrefix(err.Error(), "All username formats failed due to invalid credentials: ") {
return nil 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. // 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. // Test connection to LDAP server.
if err := l.testConnection(); err != nil { 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 // Group search params configuration

View File

@ -27,7 +27,7 @@ import (
) )
// SetNotifyKafka - helper for config migration from older config. // 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 { if !cfg.Enable {
return nil return nil
} }
@ -36,7 +36,7 @@ func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error {
return err return err
} }
s[config.NotifyKafkaSubSys][kName] = config.KVS{ s[config.NotifyKafkaSubSys][name] = config.KVS{
config.KV{ config.KV{
Key: config.Enable, Key: config.Enable,
Value: config.EnableOn, Value: config.EnableOn,

View File

@ -622,7 +622,7 @@ func (z *erasureServerPools) GetObjectNInfo(ctx context.Context, bucket, object
} }
wg.Wait() wg.Wait()
var found int = -1 var found = -1
for i, err := range errs { for i, err := range errs {
if err == nil { if err == nil {
found = i found = i
@ -683,7 +683,7 @@ func (z *erasureServerPools) GetObjectInfo(ctx context.Context, bucket, object s
} }
wg.Wait() wg.Wait()
var found int = -1 var found = -1
for i, err := range errs { for i, err := range errs {
if err == nil { if err == nil {
found = i found = i

View File

@ -495,8 +495,5 @@ func migrateCacheFormatJSON(cacheFormatPath string) error {
formatV2.Version = formatMetaVersion1 formatV2.Version = formatMetaVersion1
formatV2.Cache = formatV1.Cache formatV2.Cache = formatV1.Cache
formatV2.Cache.Version = formatCacheVersionV2 formatV2.Cache.Version = formatCacheVersionV2
if err := jsonSave(f, formatV2); err != nil { return jsonSave(f, formatV2)
return err
}
return nil
} }

View File

@ -49,7 +49,7 @@ const (
) )
// tierConfigPath refers to remote tier config object name // 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. // TierConfigMgr holds the collection of remote tiers configured in this deployment.
type TierConfigMgr struct { type TierConfigMgr struct {

View File

@ -140,10 +140,7 @@ func (r Rule) validateStatus() error {
} }
func (r Rule) validateFilter() error { func (r Rule) validateFilter() error {
if err := r.Filter.Validate(); err != nil { return r.Filter.Validate()
return err
}
return nil
} }
// Prefix - a rule can either have prefix under <filter></filter> or under // Prefix - a rule can either have prefix under <filter></filter> or under

View File

@ -205,16 +205,12 @@ func (target *AMQPTarget) send(eventData event.Event, ch *amqp.Channel) error {
return err 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{ target.args.Immediate, amqp.Publishing{
ContentType: "application/json", ContentType: "application/json",
DeliveryMode: target.args.DeliveryMode, DeliveryMode: target.args.DeliveryMode,
Body: data, 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. // Save - saves the events to the store which will be replayed when the amqp connection is active.

View File

@ -103,11 +103,7 @@ func (r *Record) WriteCSV(writer io.Writer, opts sql.WriteCSVOpts) error {
return err return err
} }
w.Flush() w.Flush()
if err := w.Error(); err != nil { return w.Error()
return err
}
return nil
} }
// WriteJSON - encodes to JSON data. // WriteJSON - encodes to JSON data.

View File

@ -145,11 +145,7 @@ func (r *Record) WriteCSV(writer io.Writer, opts sql.WriteCSVOpts) error {
return err return err
} }
w.Flush() w.Flush()
if err := w.Error(); err != nil { return w.Error()
return err
}
return nil
} }
// Raw - returns the underlying representation. // Raw - returns the underlying representation.

View File

@ -181,11 +181,7 @@ allElems:
return err return err
} }
w.Flush() w.Flush()
if err := w.Error(); err != nil { return w.Error()
return err
}
return nil
} }
// Raw - returns the underlying representation. // Raw - returns the underlying representation.