From 5c8aa65ae92b002fcc1a74c433ffd9b24b74970b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flc=E3=82=9B?= Date: Fri, 5 Jan 2024 23:32:32 +0800 Subject: [PATCH] chore(lint): Optimize a large number of lint detection issues (#57) * build(lint): Added lint detection * chore(lint): Optimize a large number of lint detection issues * chore(lint): Optimize a large number of lint detection issues * chore(lint): Optimize a large number of lint detection issues --- .golangci.yml | 28 ++++++++++++++ Makefile | 9 +++++ bytes/size.go | 6 +-- cache/redis/store.go | 70 ++++++++++++++++++++--------------- cache/repository.go | 29 +++++++++------ codec/example_test.go | 3 +- codec/json/json_test.go | 7 ++-- crontab/mutex.go | 4 +- crontab/mutex/redis/mutex.go | 2 +- crontab/server.go | 4 +- debug/dump_test.go | 2 +- errors/errors.go | 1 + gorm/adapter/logger.go | 30 +++++++-------- hashing/md5/hasher.go | 2 - helper/helper.go | 2 +- helper/helper_test.go | 6 +-- log/stack/stack_test.go | 12 +++--- middleware/cors/cors_test.go | 8 ---- strings/strings.go | 4 +- udp/server.go | 9 ++--- udp/server_test.go | 4 +- x/log/manager/manager.go | 4 +- x/log/manager/manager_test.go | 8 ++-- 23 files changed, 149 insertions(+), 105 deletions(-) create mode 100644 .golangci.yml create mode 100644 Makefile delete mode 100644 middleware/cors/cors_test.go diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..0a3fb907 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,28 @@ +linters: + disable-all: true + + enable: + - bodyclose + - dogsled + - durationcheck + - errcheck + - exportloopref + - govet + - gosimple + - gofmt + - gofumpt + - goconst + - goimports + - gomnd + - gocyclo + - ineffassign + - lll + - prealloc + - revive + - staticcheck + - typecheck + - unused + - whitespace + - wastedassign + - unconvert + - misspell \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..ea98651f --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: lint +lint: + golangci-lint run + @echo "Linting complete" + +.PHONY: fix +fix: + golangci-lint run --fix + @echo "Lint fixing complete" \ No newline at end of file diff --git a/bytes/size.go b/bytes/size.go index d1f0fe16..5e5ec3a6 100644 --- a/bytes/size.go +++ b/bytes/size.go @@ -8,7 +8,7 @@ import ( type Bytes int64 const ( - KB Bytes = 1 << (10 * (iota + 1)) + KB Bytes = 1 << (10 * (iota + 1)) //nolint:gomnd MB GB TB @@ -83,7 +83,7 @@ func (b Bytes) EB() float64 { } func (b Bytes) HumanizeValue(lens ...int) string { - var l = 2 + l := 2 if len(lens) > 0 { l = lens[0] } @@ -92,5 +92,5 @@ func (b Bytes) HumanizeValue(lens ...int) string { } func (b Bytes) Humanize(lens ...int) string { - return fmt.Sprintf("%s", b.HumanizeValue(lens...)) + b.Unit() + return b.HumanizeValue(lens...) + b.Unit() } diff --git a/cache/redis/store.go b/cache/redis/store.go index c69d8e3f..30e008a4 100644 --- a/cache/redis/store.go +++ b/cache/redis/store.go @@ -38,9 +38,7 @@ func Codec(codec codec.Codec) Option { } } -var ( - _ cache.Store = (*Store)(nil) -) +var _ cache.Store = (*Store)(nil) func New(redis redis.Cmdable, opts ...Option) *Store { opt := &options{ @@ -58,71 +56,85 @@ func New(redis redis.Cmdable, opts ...Option) *Store { } func (s *Store) Has(ctx context.Context, key string) (bool, error) { - if r := s.redis.Exists(ctx, s.opts.prefix+key); r.Err() != nil { + r := s.redis.Exists(ctx, s.opts.prefix+key) + if r.Err() != nil { return false, r.Err() - } else { - return r.Val() > 0, nil } + + return r.Val() > 0, nil } func (s *Store) Get(ctx context.Context, key string, dest interface{}) error { - if r := s.redis.Get(ctx, s.opts.prefix+key); r.Err() != nil { + r := s.redis.Get(ctx, s.opts.prefix+key) + if r.Err() != nil { return r.Err() - } else { - return s.opts.codec.Unmarshal([]byte(r.Val()), dest) } + + return s.opts.codec.Unmarshal([]byte(r.Val()), dest) } func (s *Store) Put(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error) { - if valued, err := s.opts.codec.Marshal(value); err != nil { + valued, err := s.opts.codec.Marshal(value) + if err != nil { return false, err - } else if r := s.redis.Set(ctx, s.opts.prefix+key, valued, ttl); r.Err() != nil { + } + + r := s.redis.Set(ctx, s.opts.prefix+key, valued, ttl) + if r.Err() != nil { return false, r.Err() - } else { - return r.Val() == "OK", nil } + + return r.Val() == "OK", nil } func (s *Store) Increment(ctx context.Context, key string, value int) (int, error) { - if r := s.redis.IncrBy(ctx, s.opts.prefix+key, int64(value)); r.Err() != nil { + r := s.redis.IncrBy(ctx, s.opts.prefix+key, int64(value)) + if r.Err() != nil { return 0, r.Err() - } else { - return int(r.Val()), nil } + + return int(r.Val()), nil } func (s *Store) Decrement(ctx context.Context, key string, value int) (int, error) { - if r := s.redis.DecrBy(ctx, s.opts.prefix+key, int64(value)); r.Err() != nil { + r := s.redis.DecrBy(ctx, s.opts.prefix+key, int64(value)) + if r.Err() != nil { return 0, r.Err() - } else { - return int(r.Val()), nil } + + return int(r.Val()), nil } func (s *Store) Forever(ctx context.Context, key string, value interface{}) (bool, error) { - if valued, err := s.opts.codec.Marshal(value); err != nil { + valued, err := s.opts.codec.Marshal(value) + if err != nil { return false, err - } else if r := s.redis.Set(ctx, s.opts.prefix+key, valued, redis.KeepTTL); r.Err() != nil { + } + + r := s.redis.Set(ctx, s.opts.prefix+key, valued, redis.KeepTTL) + if r.Err() != nil { return false, r.Err() - } else { - return r.Val() == "OK", nil } + + return r.Val() == "OK", nil } func (s *Store) Forget(ctx context.Context, key string) (bool, error) { - if r := s.redis.Del(ctx, s.opts.prefix+key); r.Err() != nil { + r := s.redis.Del(ctx, s.opts.prefix+key) + if r.Err() != nil { return false, r.Err() - } else { - return r.Val() > 0, nil } + + return r.Val() > 0, nil } func (s *Store) Flush(ctx context.Context) (bool, error) { - if r := s.redis.FlushAll(ctx); r.Err() != nil { + r := s.redis.FlushAll(ctx) + if r.Err() != nil { return false, r.Err() - } else { - return r.Val() == "OK", nil } + + return r.Val() == "OK", nil } func (s *Store) GetPrefix() string { diff --git a/cache/repository.go b/cache/repository.go index 98be7efe..f2c12dee 100644 --- a/cache/repository.go +++ b/cache/repository.go @@ -28,12 +28,14 @@ func NewRepository(store Store) Repository { } func (r *repository) Missing(ctx context.Context, key string) (bool, error) { - if had, err := r.Store.Has(ctx, key); err != nil { + had, err := r.Store.Has(ctx, key) + if err != nil { return false, err - } else { - return !had, nil } + + return !had, nil } + func (r *repository) Add(ctx context.Context, key string, value interface{}, ttl time.Duration) (bool, error) { // if the store is addable, use it if store, ok := r.Store.(Addable); ok { @@ -44,14 +46,14 @@ func (r *repository) Add(ctx context.Context, key string, value interface{}, ttl if missing, err := r.Missing(ctx, key); err != nil { return false, err } else if missing { - if status, err := r.Set(ctx, key, value, ttl); err != nil { + status, err := r.Set(ctx, key, value, ttl) + if err != nil { return false, err - } else { - return status, nil } - } else { - return false, nil + return status, nil } + + return false, nil } func (r *repository) Delete(ctx context.Context, key string) (bool, error) { @@ -62,7 +64,12 @@ func (r *repository) Set(ctx context.Context, key string, value interface{}, ttl return r.Put(ctx, key, value, ttl) } -func (r *repository) Remember(ctx context.Context, key string, dest interface{}, value func() interface{}, ttl time.Duration) error { +func (r *repository) Remember( + ctx context.Context, + key string, dest interface{}, + value func() interface{}, + ttl time.Duration, +) error { if missing, err := r.Missing(ctx, key); err != nil { return err } else if missing { @@ -73,7 +80,7 @@ func (r *repository) Remember(ctx context.Context, key string, dest interface{}, } return helper.ValueOf(v, dest) - } else { - return r.Get(ctx, key, dest) } + + return r.Get(ctx, key, dest) } diff --git a/codec/example_test.go b/codec/example_test.go index 1b326fd2..2c646fce 100644 --- a/codec/example_test.go +++ b/codec/example_test.go @@ -2,13 +2,14 @@ package codec_test import ( "log" + "testing" "github.com/go-kratos-ecosystem/components/v2/codec/json" ) var j = json.Codec -func ExampleJSON() { +func TestJson(_ *testing.T) { bytes, err := j.Marshal(map[string]string{ "key": "value", }) diff --git a/codec/json/json_test.go b/codec/json/json_test.go index b9b76e59..9802b112 100644 --- a/codec/json/json_test.go +++ b/codec/json/json_test.go @@ -8,11 +8,11 @@ import ( ) func TestJSON(t *testing.T) { - var j1, j2 = Codec, Codec + j1, j2 := Codec, Codec assert.Same(t, j1, j2) - var data = map[string]interface{}{ + data := map[string]interface{}{ "foo": "bar", } @@ -26,10 +26,9 @@ func TestJSON(t *testing.T) { assert.Equal(t, bytes1, bytes2) // unmarshal - var dest1, dest2 = make(map[string]interface{}), make(map[string]interface{}) + dest1, dest2 := make(map[string]interface{}), make(map[string]interface{}) assert.NoError(t, json.Unmarshal(bytes1, &dest1)) assert.NoError(t, j1.Unmarshal(bytes1, &dest2)) assert.Equal(t, dest1, dest2) - } diff --git a/crontab/mutex.go b/crontab/mutex.go index cb17262e..324bdcdc 100644 --- a/crontab/mutex.go +++ b/crontab/mutex.go @@ -5,9 +5,7 @@ import ( "errors" ) -var ( - ErrAnotherServerRunning = errors.New("crontab: another server running") -) +var ErrAnotherServerRunning = errors.New("crontab: another server running") type Mutex interface { Lock(ctx context.Context, name string) error diff --git a/crontab/mutex/redis/mutex.go b/crontab/mutex/redis/mutex.go index 8332a715..f0f53110 100644 --- a/crontab/mutex/redis/mutex.go +++ b/crontab/mutex/redis/mutex.go @@ -29,7 +29,7 @@ func WithExpired(expired time.Duration) Option { func New(redis redis.Cmdable, opts ...Option) *Mutex { m := &Mutex{ Cmdable: redis, - expired: time.Second * 60, + expired: time.Second * 60, //nolint:gomnd serverid: uuid.New().String(), } diff --git a/crontab/server.go b/crontab/server.go index 50846cf9..0e36b72c 100644 --- a/crontab/server.go +++ b/crontab/server.go @@ -69,7 +69,7 @@ func (s *Server) Start(ctx context.Context) error { s.cron.Stop() } - s.mutex.Unlock(ctx, s.name) + s.mutex.Unlock(ctx, s.name) //nolint:errcheck timer.Stop() }() @@ -106,7 +106,7 @@ func (s *Server) start() { s.log("crontab: server started") } -func (s *Server) Stop(ctx context.Context) error { +func (s *Server) Stop(_ context.Context) error { s.log("crontab: server stopping") close(s.stoped) diff --git a/debug/dump_test.go b/debug/dump_test.go index f3b2278e..cf7bc90b 100644 --- a/debug/dump_test.go +++ b/debug/dump_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -func TestDump(t *testing.T) { +func TestDump(_ *testing.T) { Dump("foo", []byte("1234567890"), &struct { Name string }{ diff --git a/errors/errors.go b/errors/errors.go index d51f14d9..6a182f7f 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -46,6 +46,7 @@ func Conflict(message string) *errors.Error { func InternalServer(message string) *errors.Error { return errors.InternalServer(http.StatusText(http.StatusInternalServerError), message) } + func ServiceUnavailable(message string) *errors.Error { return errors.ServiceUnavailable(http.StatusText(http.StatusServiceUnavailable), message) } diff --git a/gorm/adapter/logger.go b/gorm/adapter/logger.go index c7a27c7c..179822fb 100644 --- a/gorm/adapter/logger.go +++ b/gorm/adapter/logger.go @@ -30,12 +30,12 @@ func NewLogger(l log.Logger, config logger.Config) logger.Interface { ) if config.Colorful { - infoStr = logger.Green + "%s\n" + logger.Reset + logger.Green + "[info] " + logger.Reset + infoStr = logger.Green + "%s\n" + logger.Reset + logger.Green + "[info] " + logger.Reset //nolint:goconst warnStr = logger.BlueBold + "%s\n" + logger.Reset + logger.Magenta + "[warn] " + logger.Reset errStr = logger.Magenta + "%s\n" + logger.Reset + logger.Red + "[error] " + logger.Reset - traceStr = logger.Green + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" - traceWarnStr = logger.Green + "%s " + logger.Yellow + "%s\n" + logger.Reset + logger.RedBold + "[%.3fms] " + logger.Yellow + "[rows:%v]" + logger.Magenta + " %s" + logger.Reset - traceErrStr = logger.RedBold + "%s " + logger.MagentaBold + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" + traceStr = logger.Green + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" //nolint:goconst,lll + traceWarnStr = logger.Green + "%s " + logger.Yellow + "%s\n" + logger.Reset + logger.RedBold + "[%.3fms] " + logger.Yellow + "[rows:%v]" + logger.Magenta + " %s" + logger.Reset //nolint:lll + traceErrStr = logger.RedBold + "%s " + logger.MagentaBold + "%s\n" + logger.Reset + logger.Yellow + "[%.3fms] " + logger.BlueBold + "[rows:%v]" + logger.Reset + " %s" //nolint:lll } return &loggerAdapter{ @@ -57,52 +57,52 @@ func (l *loggerAdapter) LogMode(level logger.LogLevel) logger.Interface { return &newLogger } -func (l *loggerAdapter) Info(ctx context.Context, s string, i ...interface{}) { +func (l *loggerAdapter) Info(_ context.Context, s string, i ...interface{}) { if l.LogLevel >= logger.Info { _ = l.Log(log.LevelInfo, fmt.Sprintf(l.infoStr+s, append([]interface{}{utils.FileWithLineNum()}, i...)...)) } } -func (l *loggerAdapter) Warn(ctx context.Context, s string, i ...interface{}) { +func (l *loggerAdapter) Warn(_ context.Context, s string, i ...interface{}) { if l.LogLevel >= logger.Warn { _ = l.Log(log.LevelWarn, fmt.Sprintf(l.warnStr+s, append([]interface{}{utils.FileWithLineNum()}, i...)...)) } } -func (l *loggerAdapter) Error(ctx context.Context, s string, i ...interface{}) { +func (l *loggerAdapter) Error(_ context.Context, s string, i ...interface{}) { if l.LogLevel >= logger.Error { _ = l.Log(log.LevelError, fmt.Sprintf(l.errStr+s, append([]interface{}{utils.FileWithLineNum()}, i...)...)) } } -func (l *loggerAdapter) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) { +func (l *loggerAdapter) Trace(_ context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) { //nolint:lll if l.LogLevel <= logger.Silent { return } elapsed := time.Since(begin) switch { - case err != nil && l.LogLevel >= logger.Error && (!errors.Is(err, logger.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError): + case err != nil && l.LogLevel >= logger.Error && (!errors.Is(err, logger.ErrRecordNotFound) || !l.IgnoreRecordNotFoundError): //nolint:lll sql, rows := fc() if rows == -1 { - _ = l.Log(log.LevelFatal, fmt.Sprintf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)) + _ = l.Log(log.LevelFatal, fmt.Sprintf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, "-", sql)) //nolint:gomnd,lll } else { - _ = l.Log(log.LevelFatal, fmt.Sprintf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, rows, sql)) + _ = l.Log(log.LevelFatal, fmt.Sprintf(l.traceErrStr, utils.FileWithLineNum(), err, float64(elapsed.Nanoseconds())/1e6, rows, sql)) //nolint:gomnd,lll } case elapsed > l.SlowThreshold && l.SlowThreshold != 0 && l.LogLevel >= logger.Warn: sql, rows := fc() slowLog := fmt.Sprintf("SLOW SQL >= %v", l.SlowThreshold) if rows == -1 { - _ = l.Log(log.LevelWarn, fmt.Sprintf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, "-", sql)) + _ = l.Log(log.LevelWarn, fmt.Sprintf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, "-", sql)) //nolint:gomnd,lll } else { - _ = l.Log(log.LevelWarn, fmt.Sprintf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql)) + _ = l.Log(log.LevelWarn, fmt.Sprintf(l.traceWarnStr, utils.FileWithLineNum(), slowLog, float64(elapsed.Nanoseconds())/1e6, rows, sql)) //nolint:gomnd,lll } case l.LogLevel == logger.Info: sql, rows := fc() if rows == -1 { - _ = l.Log(log.LevelInfo, fmt.Sprintf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql)) + _ = l.Log(log.LevelInfo, fmt.Sprintf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, "-", sql)) //nolint:gomnd,lll } else { - _ = l.Log(log.LevelInfo, fmt.Sprintf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, rows, sql)) + _ = l.Log(log.LevelInfo, fmt.Sprintf(l.traceStr, utils.FileWithLineNum(), float64(elapsed.Nanoseconds())/1e6, rows, sql)) //nolint:gomnd,lll } } } diff --git a/hashing/md5/hasher.go b/hashing/md5/hasher.go index b077dda2..359de23e 100644 --- a/hashing/md5/hasher.go +++ b/hashing/md5/hasher.go @@ -33,7 +33,6 @@ func (h *hasher) Make(value string) (string, error) { // MustMake generates a new hashed value. func (h *hasher) MustMake(value string) string { hashedValue, err := h.Make(value) - if err != nil { panic(err) } @@ -44,7 +43,6 @@ func (h *hasher) MustMake(value string) string { // Check checks the given value and hashed value. func (h *hasher) Check(value, hashedValue string) bool { hv, err := h.Make(value) - if err != nil { return false } diff --git a/helper/helper.go b/helper/helper.go index 31d6af4f..99ca3eff 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -74,7 +74,7 @@ func CallWithCtx(ctx interface{}, fn interface{}, params ...interface{}) interfa panic("fn must be a function") } - var args []reflect.Value + var args []reflect.Value //nolint:prealloc if ctx != nil { args = append(args, reflect.ValueOf(ctx)) diff --git a/helper/helper_test.go b/helper/helper_test.go index 86c88b04..0f3f039d 100644 --- a/helper/helper_test.go +++ b/helper/helper_test.go @@ -21,7 +21,7 @@ func TestTap(t *testing.T) { assert.Equal(t, "foo", f.Name) f = Tap(&Foo{Name: "foo"}, func(foo interface{}) { - foo.(*Foo).Name = "bar" + foo.(*Foo).Name = "bar" //nolint:goconst }).(*Foo) assert.Equal(t, "bar", f.Name) @@ -145,7 +145,7 @@ func TestCallWithCtx(t *testing.T) { func TestRetry(t *testing.T) { t.Run("retry 3 times, and the result is an error", func(t *testing.T) { - var i = 1 + i := 1 err := Retry(func() error { i++ @@ -157,7 +157,7 @@ func TestRetry(t *testing.T) { }) t.Run("retry 3 times, and the result is nil", func(t *testing.T) { - var i = 1 + i := 1 err := Retry(func() error { i++ diff --git a/log/stack/stack_test.go b/log/stack/stack_test.go index 4efb5d4c..3b5d27ca 100644 --- a/log/stack/stack_test.go +++ b/log/stack/stack_test.go @@ -36,7 +36,7 @@ func (t *testLogger) Log(level log.Level, keyvals ...interface{}) error { type errorLogger struct{} -func (t *errorLogger) Log(level log.Level, keyvals ...interface{}) error { +func (t *errorLogger) Log(_ log.Level, _ ...interface{}) error { return fmt.Errorf("error") } @@ -55,11 +55,13 @@ func TestStackLogger(t *testing.T) { name: "debug", level: log.LevelDebug, want: "name: log1, level: DEBUG, keyvals: [test test]\nname: log2, level: DEBUG, keyvals: [test test]\n", - }, { + }, + { name: "info", level: log.LevelInfo, want: "name: log1, level: INFO, keyvals: [test test]\nname: log2, level: INFO, keyvals: [test test]\n", - }, { + }, + { name: "warn", level: log.LevelWarn, want: "name: log1, level: WARN, keyvals: [test test]\nname: log2, level: WARN, keyvals: [test test]\n", @@ -79,7 +81,7 @@ func TestStackLogger(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { buf, err := redirectStdout(func() { - logger.Log(tt.level, "test", "test") + _ = logger.Log(tt.level, "test", "test") }) if err != nil { t.Fatal(err) @@ -124,7 +126,7 @@ func TestIgnoreExceptions(t *testing.T) { }, opts...) buf, err := redirectStdout(func() { - logger.Log(log.LevelDebug, "test", "test") + _ = logger.Log(log.LevelDebug, "test", "test") }) if err != nil { t.Fatal(err) diff --git a/middleware/cors/cors_test.go b/middleware/cors/cors_test.go deleted file mode 100644 index f0049aad..00000000 --- a/middleware/cors/cors_test.go +++ /dev/null @@ -1,8 +0,0 @@ -package cors - -import ( - "testing" -) - -func TestCors(t *testing.T) { -} diff --git a/strings/strings.go b/strings/strings.go index 14b7864c..2d0c6b5f 100644 --- a/strings/strings.go +++ b/strings/strings.go @@ -123,8 +123,8 @@ func Shuffle(s string) string { // // Random(10) // "qujrlkhyqr" func Random(length int) string { - var letters = []rune(randomLetters) - var lettersLength = len(letters) + letters := []rune(randomLetters) + lettersLength := len(letters) b := make([]rune, length) diff --git a/udp/server.go b/udp/server.go index 3ccc7e68..645d6e6d 100644 --- a/udp/server.go +++ b/udp/server.go @@ -68,8 +68,8 @@ func WithReadChanSize(readChanSize int) Option { func NewServer(address string, opts ...Option) *Server { s := &Server{ address: address, - bufSize: 1024, - readChanSize: 1024, + bufSize: 1024, //nolint:gomnd + readChanSize: 1024, //nolint:gomnd stoped: make(chan struct{}), } @@ -82,7 +82,7 @@ func NewServer(address string, opts ...Option) *Server { return s } -func (s *Server) Start(ctx context.Context) (err error) { +func (s *Server) Start(_ context.Context) (err error) { s.conn, err = net.ListenPacket("udp", s.address) if err != nil { return @@ -107,7 +107,6 @@ func (s *Server) Start(ctx context.Context) (err error) { Body: buf[:n], } } - } func (s *Server) start() { @@ -135,7 +134,7 @@ func (s *Server) handle(message *Message) { s.handler(message) } -func (s *Server) Stop(ctx context.Context) error { +func (s *Server) Stop(_ context.Context) error { log.Println("udp server: stopping") s.stop() diff --git a/udp/server_test.go b/udp/server_test.go index b59636f7..10555b61 100644 --- a/udp/server_test.go +++ b/udp/server_test.go @@ -26,10 +26,10 @@ func TestServer(t *testing.T) { t.Log(err) }), WithBufSize(1024)) - go server.Start(context.Background()) + go server.Start(context.Background()) //nolint:errcheck time.Sleep(time.Second * 5) - server.Stop(context.Background()) + _ = server.Stop(context.Background()) }() go func() { diff --git a/x/log/manager/manager.go b/x/log/manager/manager.go index 6285f914..77f3dcc7 100644 --- a/x/log/manager/manager.go +++ b/x/log/manager/manager.go @@ -7,9 +7,7 @@ import ( "github.com/go-kratos/kratos/v2/log" ) -var ( - ErrNoDefaultLogger = errors.New("log manager: no default logger") -) +var ErrNoDefaultLogger = errors.New("log manager: no default logger") type Config struct { Default string diff --git a/x/log/manager/manager_test.go b/x/log/manager/manager_test.go index b5762ff6..fdf41b78 100644 --- a/x/log/manager/manager_test.go +++ b/x/log/manager/manager_test.go @@ -24,12 +24,12 @@ func TestManager_Channel(t *testing.T) { }, }) - m.Log(log.LevelDebug, "test", "test") - m.Channel("test").Log(log.LevelDebug, "test", "test") - m.Channel("ts").Log(log.LevelDebug, "test", "test") + m.Log(log.LevelDebug, "test", "test") //nolint:errcheck + m.Channel("test").Log(log.LevelDebug, "test", "test") //nolint:errcheck + m.Channel("ts").Log(log.LevelDebug, "test", "test") //nolint:errcheck assert.Panics(t, func() { - m.Channel("unknown").Log(log.LevelDebug, "test", "test") + m.Channel("unknown").Log(log.LevelDebug, "test", "test") //nolint:errcheck }) }