Lint
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
2ead56e2b1
commit
7f1ad192a2
123
.golangci.yml
123
.golangci.yml
|
@ -1,23 +1,116 @@
|
||||||
|
# This file contains all available configuration options
|
||||||
|
# with their default values.
|
||||||
|
|
||||||
|
# options for analysis running
|
||||||
run:
|
run:
|
||||||
|
# default concurrency is a available CPU number
|
||||||
|
#concurrency: 4
|
||||||
|
|
||||||
|
# timeout for analysis, e.g. 30s, 5m, default is 1m
|
||||||
|
deadline: 30m
|
||||||
|
|
||||||
|
# include test files or not, default is true
|
||||||
tests: false
|
tests: false
|
||||||
|
|
||||||
|
# which dirs to skip: they won't be analyzed;
|
||||||
|
# can use regexp here: generated.*, regexp is applied on full path;
|
||||||
|
# default value is empty list, but next dirs are always skipped independently
|
||||||
|
# from this option's value:
|
||||||
|
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
|
||||||
|
skip-dirs:
|
||||||
|
- bin$
|
||||||
|
- \.git$
|
||||||
|
- etc$
|
||||||
|
- protobuf$
|
||||||
|
- scripts$
|
||||||
|
- vendor$
|
||||||
|
- ^benches/
|
||||||
|
|
||||||
|
# which files to skip: they will be analyzed, but issues from them
|
||||||
|
# won't be reported. Default value is empty list, but there is
|
||||||
|
# no need to include all autogenerated files, we confidently recognize
|
||||||
|
# autogenerated files. If it's not please let us know.
|
||||||
|
skip-files:
|
||||||
|
- "_easyjson.go"
|
||||||
|
- ".pb.go"
|
||||||
|
|
||||||
|
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
|
||||||
|
# If invoked with -mod=readonly, the go command is disallowed from the implicit
|
||||||
|
# automatic updating of go.mod described above. Instead, it fails when any changes
|
||||||
|
# to go.mod are needed. This setting is most useful to check that go.mod does
|
||||||
|
# not need updates, such as in a continuous integration and testing system.
|
||||||
|
# If invoked with -mod=vendor, the go command assumes that the vendor
|
||||||
|
# directory holds the correct copies of dependencies and ignores
|
||||||
|
# the dependency descriptions in go.mod.
|
||||||
|
modules-download-mode: mod
|
||||||
|
|
||||||
|
# all available settings of specific linters
|
||||||
|
linters-settings:
|
||||||
|
errcheck:
|
||||||
|
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
|
||||||
|
# default is false: such cases aren't reported by default.
|
||||||
|
check-blank: true
|
||||||
|
govet:
|
||||||
|
# report about shadowed variables
|
||||||
|
check-shadowing: true
|
||||||
|
golint:
|
||||||
|
# minimal confidence for issues, default is 0.8
|
||||||
|
min-confidence: 0.3
|
||||||
|
gocyclo:
|
||||||
|
# minimal code complexity to report, 30 by default (but we recommend 10-20)
|
||||||
|
min-complexity: 20
|
||||||
|
dupl:
|
||||||
|
# tokens count to trigger issue, 150 by default
|
||||||
|
threshold: 200
|
||||||
|
lll:
|
||||||
|
# max line length, lines longer will be reported. Default is 120.
|
||||||
|
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
|
||||||
|
line-length: 150
|
||||||
|
funlen:
|
||||||
|
statements: 50
|
||||||
|
lines: 150
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: false
|
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
- gochecknoglobals
|
- gci
|
||||||
- gochecknoinits
|
|
||||||
- godox
|
|
||||||
- goerr113
|
|
||||||
- gomnd
|
|
||||||
- lll
|
|
||||||
- nakedret
|
|
||||||
- testpackage
|
|
||||||
- wsl
|
|
||||||
- nlreturn
|
|
||||||
- whitespace
|
|
||||||
- bodyclose
|
|
||||||
- wrapcheck
|
|
||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
|
- exhaustruct
|
||||||
|
- gochecknoglobals
|
||||||
|
- whitespace
|
||||||
|
- wsl
|
||||||
|
- wrapcheck
|
||||||
|
- nlreturn
|
||||||
|
- gofmt
|
||||||
|
- gofumpt
|
||||||
|
- varcheck
|
||||||
|
- golint
|
||||||
|
- structcheck
|
||||||
|
- nosnakecase
|
||||||
|
- maligned
|
||||||
|
- interfacer
|
||||||
|
- deadcode
|
||||||
|
- scopelint
|
||||||
|
- ifshort
|
||||||
|
- godox
|
||||||
|
- forbidigo
|
||||||
|
- goerr113
|
||||||
|
- nonamedreturns
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- gofumpt
|
fast: false
|
||||||
|
|
||||||
|
issues:
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
max-same-issues: 0
|
||||||
|
|
||||||
|
exclude-rules:
|
||||||
|
# Exclude lll issues for long lines with go:generate
|
||||||
|
- linters:
|
||||||
|
- lll
|
||||||
|
source: "^//go:generate "
|
||||||
|
- linters:
|
||||||
|
- golint
|
||||||
|
text: "receiver name should be a reflection of its identity"
|
||||||
|
|
||||||
|
output:
|
||||||
|
format: tab
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ PROJECT_NAME=modules
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
lint: ## Линт всего проекта
|
lint: ## Линт всего проекта
|
||||||
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.51.1
|
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(go env GOPATH)/bin v1.51.1
|
||||||
golangci-lint run --config=./golangci.yml ./...
|
golangci-lint run --config=./.golangci.yml ./...
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: ## Юнит тестирование всего проекта
|
test: ## Юнит тестирование всего проекта
|
||||||
|
|
|
@ -33,22 +33,22 @@ func New(str interface{}) Interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method wraps discrete methods.
|
// Method wraps discrete methods.
|
||||||
func (s Interface) Combine(c Config) error {
|
func (s Interface) Combine(config Config) error {
|
||||||
if c.ConfigFile != "" {
|
if config.ConfigFile != "" {
|
||||||
fmt.Printf("try to apply config from file %s...\n", c.ConfigFile)
|
fmt.Printf("try to apply config from file %s...\n", config.ConfigFile)
|
||||||
if err := s.SetFromFile(c.ConfigFile); err != nil {
|
if err := s.SetFromFile(config.ConfigFile); err != nil {
|
||||||
return fmt.Errorf("can't apply config from file: %w", err)
|
return fmt.Errorf("can't apply config from file: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.EnvPrefix != "" {
|
if config.EnvPrefix != "" {
|
||||||
fmt.Printf("try to apply config from environment...\n")
|
fmt.Printf("try to apply config from environment...\n")
|
||||||
if err := s.SetFromEnv(c.EnvPrefix); err != nil {
|
if err := s.SetFromEnv(config.EnvPrefix); err != nil {
|
||||||
return fmt.Errorf("can't apply envvars to config:%w", err)
|
return fmt.Errorf("can't apply envvars to config:%w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if c.DSN != "" {
|
if config.DSN != "" {
|
||||||
fmt.Printf("try to apply config from DSN %s...\n", c.DSN)
|
fmt.Printf("try to apply config from DSN %s...\n", config.DSN)
|
||||||
db, dbname, err := DialDSN(c.DSN)
|
db, dbname, err := DialDSN(config.DSN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't dial DB:%w", err)
|
return fmt.Errorf("can't dial DB:%w", err)
|
||||||
}
|
}
|
||||||
|
@ -109,15 +109,15 @@ func DialDSN(dsn string) (db *sql.DB, dbname string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method adds and replace config fields from db.
|
// Method adds and replace config fields from db.
|
||||||
func (s Interface) SetFromDB(db *sql.DB, dbname string) error {
|
func (s Interface) SetFromDB(database *sql.DB, dbname string) error {
|
||||||
defer db.Close()
|
defer database.Close()
|
||||||
res := make(map[string]string)
|
res := make(map[string]string)
|
||||||
var key, val string
|
var key, val string
|
||||||
|
|
||||||
//TODO: Перенести это в параметры.
|
//TODO: Перенести это в параметры.
|
||||||
table := "config"
|
table := "config"
|
||||||
q := "SELECT " + table + ".key, " + table + ".value FROM " + table
|
q := "SELECT " + table + ".key, " + table + ".value FROM " + table
|
||||||
results, err := db.Query(q)
|
results, err := database.Query(q)
|
||||||
if err != nil || results.Err() != nil {
|
if err != nil || results.Err() != nil {
|
||||||
return fmt.Errorf("can't get key-value pairs from DB: %w", err)
|
return fmt.Errorf("can't get key-value pairs from DB: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,27 +8,27 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) error {
|
func getEnvVar(value reflect.Value, rtype reflect.Type, counter int, prefix string) error {
|
||||||
if v.Kind() != reflect.Ptr {
|
if value.Kind() != reflect.Ptr {
|
||||||
return fmt.Errorf("not a pointer value")
|
return fmt.Errorf("not a pointer value")
|
||||||
}
|
}
|
||||||
f := reflect.StructField{}
|
f := reflect.StructField{}
|
||||||
if counter != -1 {
|
if counter != -1 {
|
||||||
f = t.Field(counter)
|
f = rtype.Field(counter)
|
||||||
}
|
}
|
||||||
v = reflect.Indirect(v)
|
value = reflect.Indirect(value)
|
||||||
fName := strings.ToUpper(f.Name)
|
fName := strings.ToUpper(f.Name)
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
prefix = strings.TrimLeft(prefix, "_")
|
prefix = strings.TrimLeft(prefix, "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
env := os.Getenv(prefix + fName)
|
env := os.Getenv(prefix + fName)
|
||||||
if err := selector(env, &v); err != nil {
|
if err := selector(env, &value); err != nil {
|
||||||
return fmt.Errorf("could set value: %w", err)
|
return fmt.Errorf("could set value: %w", err)
|
||||||
}
|
}
|
||||||
if v.Kind() == reflect.Struct {
|
if value.Kind() == reflect.Struct {
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < value.NumField(); i++ {
|
||||||
if err := getEnvVar(v.Field(i).Addr(), v.Type(), i, prefix+fName+"_"); err != nil {
|
if err := getEnvVar(value.Field(i).Addr(), value.Type(), i, prefix+fName+"_"); err != nil {
|
||||||
return fmt.Errorf("could not apply env var: %w", err)
|
return fmt.Errorf("could not apply env var: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,27 +36,27 @@ func getEnvVar(v reflect.Value, t reflect.Type, counter int, prefix string) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseToStruct(v reflect.Value, t reflect.Type, counter int, prefix string, kv map[string]string) error {
|
func parseToStruct(value reflect.Value, rtype reflect.Type, counter int, prefix string, index map[string]string) error {
|
||||||
if v.Kind() != reflect.Ptr {
|
if value.Kind() != reflect.Ptr {
|
||||||
return fmt.Errorf("not a pointer value")
|
return fmt.Errorf("not a pointer value")
|
||||||
}
|
}
|
||||||
f := reflect.StructField{}
|
f := reflect.StructField{}
|
||||||
if counter != -1 {
|
if counter != -1 {
|
||||||
f = t.Field(counter)
|
f = rtype.Field(counter)
|
||||||
}
|
}
|
||||||
v = reflect.Indirect(v)
|
value = reflect.Indirect(value)
|
||||||
fName := strings.ToLower(f.Name)
|
fName := strings.ToLower(f.Name)
|
||||||
if prefix != "" {
|
if prefix != "" {
|
||||||
prefix = strings.TrimLeft(prefix, ".")
|
prefix = strings.TrimLeft(prefix, ".")
|
||||||
}
|
}
|
||||||
|
|
||||||
env := kv[prefix+fName]
|
env := index[prefix+fName]
|
||||||
if err := selector(env, &v); err != nil {
|
if err := selector(env, &value); err != nil {
|
||||||
return fmt.Errorf("could set value: %w", err)
|
return fmt.Errorf("could set value: %w", err)
|
||||||
}
|
}
|
||||||
if v.Kind() == reflect.Struct {
|
if value.Kind() == reflect.Struct {
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < value.NumField(); i++ {
|
||||||
if err := parseToStruct(v.Field(i).Addr(), v.Type(), i, prefix+fName+".", kv); err != nil {
|
if err := parseToStruct(value.Field(i).Addr(), value.Type(), i, prefix+fName+".", index); err != nil {
|
||||||
return fmt.Errorf("could not apply env var: %w", err)
|
return fmt.Errorf("could not apply env var: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,24 +64,24 @@ func parseToStruct(v reflect.Value, t reflect.Type, counter int, prefix string,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func selector(env string, v *reflect.Value) error {
|
func selector(env string, value *reflect.Value) error {
|
||||||
if env != "" {
|
if env != "" {
|
||||||
switch v.Kind() {
|
//nolint:exhaustive
|
||||||
|
switch value.Kind() {
|
||||||
case reflect.Int:
|
case reflect.Int:
|
||||||
envI, err := strconv.Atoi(env)
|
envI, err := strconv.Atoi(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not parse to int: %w", err)
|
return fmt.Errorf("could not parse to int: %w", err)
|
||||||
}
|
}
|
||||||
v.SetInt(int64(envI))
|
value.SetInt(int64(envI))
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
v.SetString(env)
|
value.SetString(env)
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
envB, err := strconv.ParseBool(env)
|
envB, err := strconv.ParseBool(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not parse bool: %w", err)
|
return fmt.Errorf("could not parse bool: %w", err)
|
||||||
}
|
}
|
||||||
v.SetBool(envB)
|
value.SetBool(envB)
|
||||||
case reflect.Array, reflect.Chan, reflect.Complex128, reflect.Complex64, reflect.Float32, reflect.Float64, reflect.Func, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int8, reflect.Interface, reflect.Invalid, reflect.Map, reflect.Ptr, reflect.Slice, reflect.Struct, reflect.Uint, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint8, reflect.Uintptr, reflect.UnsafePointer:
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//nolint:asasalint,ireturn
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -34,7 +35,7 @@ func New(conf Config) (Interface, error) {
|
||||||
return nil, errors.New("invalid logger config")
|
return nil, errors.New("invalid logger config")
|
||||||
}
|
}
|
||||||
|
|
||||||
c := amitralog.Configuration{
|
config := amitralog.Configuration{
|
||||||
EnableConsole: !conf.MuteStdout,
|
EnableConsole: !conf.MuteStdout,
|
||||||
ConsoleLevel: amitralog.Fatal,
|
ConsoleLevel: amitralog.Fatal,
|
||||||
ConsoleJSONFormat: false,
|
ConsoleJSONFormat: false,
|
||||||
|
@ -44,7 +45,7 @@ func New(conf Config) (Interface, error) {
|
||||||
FileLocation: conf.File,
|
FileLocation: conf.File,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := amitralog.NewLogger(c, amitralog.InstanceZapLogger); err != nil {
|
if err := amitralog.NewLogger(config, amitralog.InstanceZapLogger); err != nil {
|
||||||
log.Fatalf("Could not instantiate log %s", err.Error())
|
log.Fatalf("Could not instantiate log %s", err.Error())
|
||||||
}
|
}
|
||||||
l := amitralog.WithFields(amitralog.Fields{"hw": "15"})
|
l := amitralog.WithFields(amitralog.Fields{"hw": "15"})
|
||||||
|
@ -70,5 +71,6 @@ func (l *Logger) Errorf(format string, args ...interface{}) {
|
||||||
|
|
||||||
func (l *Logger) Fatalf(format string, args ...interface{}) {
|
func (l *Logger) Fatalf(format string, args ...interface{}) {
|
||||||
l.Logger.Fatalf(format, args)
|
l.Logger.Fatalf(format, args)
|
||||||
|
//nolint:gomnd
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue