Skip to content

Commit

Permalink
chore(lint): Optimize a large number of lint detection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Jan 5, 2024
1 parent 456e986 commit 0dd406f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
21 changes: 0 additions & 21 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ linters:
disable-all: true

enable:
# - gosimple
# - govet
# - ineffassign
# - staticcheck
# - bodyclose
# - dupl
# - exportloopref
# - funlen
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - stylecheck
# - whitespace
# - goprintffuncname
# - gosec
# - interfacer
# - maligned
# - prealloc
# - revive
# - errorlint
- bodyclose
- dogsled
- durationcheck
Expand Down
38 changes: 24 additions & 14 deletions cache/redis/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ func (s *Store) Get(ctx context.Context, key string, dest interface{}) error {
}

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) {
Expand All @@ -102,29 +106,35 @@ func (s *Store) Decrement(ctx context.Context, key string, value int) (int, erro
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion crontab/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions gorm/adapter/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion helper/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions udp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -134,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()
Expand Down

0 comments on commit 0dd406f

Please sign in to comment.