1
0
mirror of https://github.com/go-kratos/kratos.git synced 2024-12-24 20:14:48 +02:00

fix: fix errors reported by Lint CI. (#3435)

* fix: fix errors reported by Lint CI.

* fix error reported by golangLintCI

* update field name to server. aviod copyloopvar check.

* fix lint problem.
This commit is contained in:
Monet Lee 2024-10-11 22:00:22 +08:00 committed by GitHub
parent 5b5c253d83
commit 7cd86eb077
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 14 additions and 13 deletions

View File

@ -31,6 +31,5 @@ jobs:
- name: Lint - name: Lint
uses: golangci/golangci-lint-action@v6 uses: golangci/golangci-lint-action@v6
with: with:
version: v1.60.3 version: v1.61.0
working-directory: ${{ matrix.workdir }} working-directory: ${{ matrix.workdir }}
skip-pkg-cache: true

View File

@ -10,8 +10,9 @@ linters:
- dogsled - dogsled
- durationcheck - durationcheck
- errcheck - errcheck
- exportloopref # - copyloopvar # need upgrade to Go 1.22
- govet - govet
- staticcheck
- gosimple - gosimple
- gofmt - gofmt
- gofumpt - gofumpt
@ -49,7 +50,8 @@ linters:
linters-settings: linters-settings:
govet: govet:
check-shadowing: true enable:
- shadow
whitespace: whitespace:
multi-func: true multi-func: true
lll: lll:

6
app.go
View File

@ -99,17 +99,17 @@ func (a *App) Run() error {
} }
} }
for _, srv := range a.opts.servers { for _, srv := range a.opts.servers {
srv := srv server := srv
eg.Go(func() error { eg.Go(func() error {
<-ctx.Done() // wait for stop signal <-ctx.Done() // wait for stop signal
stopCtx, cancel := context.WithTimeout(NewContext(a.opts.ctx, a), a.opts.stopTimeout) stopCtx, cancel := context.WithTimeout(NewContext(a.opts.ctx, a), a.opts.stopTimeout)
defer cancel() defer cancel()
return srv.Stop(stopCtx) return server.Stop(stopCtx)
}) })
wg.Add(1) wg.Add(1)
eg.Go(func() error { eg.Go(func() error {
wg.Done() // here is to ensure server start has begun running before register, so defer is not needed wg.Done() // here is to ensure server start has begun running before register, so defer is not needed
return srv.Start(NewContext(a.opts.ctx, a)) return server.Start(NewContext(a.opts.ctx, a))
}) })
} }
wg.Wait() wg.Wait()

View File

@ -584,7 +584,7 @@ func TestRegistry_IdleAndWatch2(t *testing.T) {
if err1 != nil { if err1 != nil {
t.Error(err1) t.Error(err1)
} }
go func(i int) { go func(_ int) {
// first // first
service, err2 := watch.Next() service, err2 := watch.Next()
if (err2 != nil) != tt.wantErr { if (err2 != nil) != tt.wantErr {

View File

@ -254,7 +254,7 @@ func (w *wrappedClientStream) Context() context.Context {
} }
func (w *wrappedClientStream) SendMsg(m interface{}) error { func (w *wrappedClientStream) SendMsg(m interface{}) error {
h := func(ctx context.Context, req interface{}) (interface{}, error) { h := func(_ context.Context, req interface{}) (interface{}, error) {
return req, w.ClientStream.SendMsg(m) return req, w.ClientStream.SendMsg(m)
} }
@ -272,7 +272,7 @@ func (w *wrappedClientStream) SendMsg(m interface{}) error {
} }
func (w *wrappedClientStream) RecvMsg(m interface{}) error { func (w *wrappedClientStream) RecvMsg(m interface{}) error {
h := func(ctx context.Context, req interface{}) (interface{}, error) { h := func(_ context.Context, req interface{}) (interface{}, error) {
return req, w.ClientStream.RecvMsg(m) return req, w.ClientStream.RecvMsg(m)
} }
@ -305,7 +305,7 @@ func streamClientInterceptor(ms []middleware.Middleware, filters []selector.Node
return nil, err return nil, err
} }
h := func(ctx context.Context, req interface{}) (interface{}, error) { h := func(_ context.Context, _ interface{}) (interface{}, error) {
return streamer, nil return streamer, nil
} }

View File

@ -80,7 +80,7 @@ func (s *Server) streamServerInterceptor() grpc.StreamServerInterceptor {
replyHeader: headerCarrier(replyHeader), replyHeader: headerCarrier(replyHeader),
}) })
h := func(ctx context.Context, req interface{}) (interface{}, error) { h := func(_ context.Context, _ interface{}) (interface{}, error) {
return handler(srv, ss), nil return handler(srv, ss), nil
} }