From 1850093a0706a6e02e9c18008dc21dd746da98ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=98=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2?= Date: Tue, 10 Sep 2024 13:14:13 +0300 Subject: [PATCH] Lint --- .golangci.yml | 13 ++----------- core/config/config.go | 5 +++-- core/config/internal.go | 5 +++-- core/logger/logger.go | 3 +-- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 22d2518..ebad992 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,7 +74,6 @@ linters: enable-all: true disable: - gci - - exhaustivestruct - exhaustruct - gochecknoglobals - whitespace @@ -83,21 +82,13 @@ linters: - nlreturn - gofmt - gofumpt - - varcheck - - golint - - structcheck - - nosnakecase - - maligned - - interfacer - - deadcode - - scopelint - - ifshort - godox - forbidigo - - goerr113 + - err113 - nonamedreturns - staticcheck - depguard + - intrange #Пока не пересели на go1.22+ fast: false issues: diff --git a/core/config/config.go b/core/config/config.go index 061420e..7f96534 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -2,6 +2,7 @@ package config import ( "database/sql" + "errors" "fmt" "io/ioutil" "os" @@ -98,7 +99,7 @@ func DialDSN(dsn string) (db *sql.DB, dbname string, err error) { driver = "mysql" dsn = strings.TrimLeft(dsn, "mysql://") default: - return nil, "", fmt.Errorf("can't use unknown SQL dialect") + return nil, "", errors.New("can't use unknown SQL dialect") } db, err = sql.Open(driver, dsn) @@ -116,7 +117,7 @@ func (s Interface) SetFromDB(database *sql.DB, _ string) error { // TODO: Перенести это в параметры. table := "config" - q := "SELECT " + table + ".key, " + table + ".value FROM " + table + q := fmt.Sprintf("SELECT %s.key, %s.value FROM %s", table, table, table) results, err := database.Query(q) if err != nil || results.Err() != nil { return fmt.Errorf("can't get key-value pairs from DB: %w", err) diff --git a/core/config/internal.go b/core/config/internal.go index 04ef788..cde5604 100644 --- a/core/config/internal.go +++ b/core/config/internal.go @@ -1,6 +1,7 @@ package config import ( + "errors" "fmt" "os" "reflect" @@ -10,7 +11,7 @@ import ( func getEnvVar(value reflect.Value, rtype reflect.Type, counter int, prefix string) error { if value.Kind() != reflect.Ptr { - return fmt.Errorf("not a pointer value") + return errors.New("not a pointer value") } f := reflect.StructField{} if counter != -1 { @@ -38,7 +39,7 @@ func getEnvVar(value reflect.Value, rtype reflect.Type, counter int, prefix stri func parseToStruct(value reflect.Value, rtype reflect.Type, counter int, prefix string, index map[string]string) error { if value.Kind() != reflect.Ptr { - return fmt.Errorf("not a pointer value") + return errors.New("not a pointer value") } f := reflect.StructField{} if counter != -1 { diff --git a/core/logger/logger.go b/core/logger/logger.go index b018d25..14d35bb 100644 --- a/core/logger/logger.go +++ b/core/logger/logger.go @@ -71,6 +71,5 @@ func (l *Logger) Errorf(format string, args ...interface{}) { func (l *Logger) Fatalf(format string, args ...interface{}) { l.Logger.Fatalf(format, args) - //nolint:gomnd - os.Exit(2) + os.Exit(2) //nolint:mnd }