From 563616e9e4b0599240ff29f586bff43ab0c161c2 Mon Sep 17 00:00:00 2001 From: demoManito <1430482733@qq.com> Date: Fri, 30 Aug 2024 19:06:09 +0800 Subject: [PATCH 1/2] chore: upgrade golangci-lint version to v1.60.3 --- .github/workflows/lint.yml | 2 +- .golangci.yml | 6 ++-- app.go | 6 ++-- cmd/kratos/internal/proto/client/client.go | 2 +- cmd/kratos/internal/run/run.go | 2 +- config/config_test.go | 3 +- config/env/env.go | 2 +- config/options.go | 4 +-- config/options_test.go | 2 +- contrib/config/nacos/config_test.go | 4 +-- contrib/opensergo/opensergo_test.go | 4 +-- contrib/polaris/router.go | 2 +- contrib/registry/consul/registry_test.go | 6 ++-- contrib/registry/etcd/registry.go | 4 +-- contrib/registry/eureka/client.go | 8 ++--- contrib/registry/kubernetes/registry.go | 6 ++-- contrib/registry/nacos/registry_test.go | 2 +- contrib/registry/nacos/watcher.go | 2 +- contrib/registry/zookeeper/register_test.go | 8 ++--- encoding/encoding_test.go | 5 ++-- encoding/form/proto_decode.go | 30 +++++++++---------- errors/errors.go | 2 +- errors/types.go | 2 +- internal/host/host.go | 2 +- internal/matcher/middleware_test.go | 4 +-- log/filter_test.go | 5 +++- log/value_test.go | 2 +- metadata/metadata_test.go | 2 +- middleware/auth/jwt/jwt_test.go | 20 ++++++------- .../circuitbreaker/circuitbreaker_test.go | 4 +-- middleware/logging/logging_test.go | 2 +- middleware/metrics/metrics.go | 2 +- middleware/metrics/metrics_test.go | 10 +++---- middleware/middleware_test.go | 6 ++-- middleware/ratelimit/ratelimit_test.go | 2 +- middleware/recovery/recovery.go | 4 +-- middleware/recovery/recovery_test.go | 6 ++-- middleware/selector/selector_test.go | 12 ++++---- middleware/tracing/span.go | 2 +- middleware/tracing/tracing_test.go | 1 - middleware/validate/validate_test.go | 2 +- options_test.go | 6 ++-- selector/node/direct/direct.go | 2 +- selector/node/ewma/node.go | 2 +- selector/selector_test.go | 2 +- transport/grpc/client.go | 4 +-- transport/grpc/client_test.go | 6 ++-- transport/grpc/server.go | 4 +-- transport/grpc/server_test.go | 12 ++++---- transport/http/binding/encode.go | 2 +- transport/http/client.go | 2 +- transport/http/client_test.go | 8 ++--- transport/http/context_test.go | 2 +- transport/http/router_test.go | 4 +-- transport/http/server.go | 6 ++-- transport/http/server_test.go | 9 +++--- 56 files changed, 137 insertions(+), 136 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e6ee064202f..75a267acea0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -31,6 +31,6 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v6 with: - version: v1.54.2 + version: v1.60.3 working-directory: ${{ matrix.workdir }} skip-pkg-cache: true diff --git a/.golangci.yml b/.golangci.yml index 556fcfbc4aa..57b20dd7612 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters: - gofumpt - goconst - goimports - - gomnd + - mnd - gocyclo - ineffassign - lll @@ -54,9 +54,9 @@ linters-settings: multi-func: true lll: line-length: 160 - gomnd: + mnd: # don't include the "operation", "argument" and "assign" - checks: + checks: - case - condition - return diff --git a/app.go b/app.go index 1fa23132e87..86a6cb5bf91 100644 --- a/app.go +++ b/app.go @@ -9,12 +9,12 @@ import ( "syscall" "time" + "github.com/google/uuid" + "golang.org/x/sync/errgroup" + "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/registry" "github.com/go-kratos/kratos/v2/transport" - - "github.com/google/uuid" - "golang.org/x/sync/errgroup" ) // AppInfo is application context value. diff --git a/cmd/kratos/internal/proto/client/client.go b/cmd/kratos/internal/proto/client/client.go index cb3f4a76d56..07e4b490941 100644 --- a/cmd/kratos/internal/proto/client/client.go +++ b/cmd/kratos/internal/proto/client/client.go @@ -72,7 +72,7 @@ func walk(dir string, args []string) error { if dir == "" { dir = "." } - return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + return filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error { if ext := filepath.Ext(path); ext != ".proto" || strings.HasPrefix(path, "third_party") { return nil } diff --git a/cmd/kratos/internal/run/run.go b/cmd/kratos/internal/run/run.go index 2def97a1f99..3137016fcf1 100644 --- a/cmd/kratos/internal/run/run.go +++ b/cmd/kratos/internal/run/run.go @@ -98,7 +98,7 @@ func findCMD(base string) (map[string]string, error) { var root bool next := func(dir string) (map[string]string, error) { cmdPath := make(map[string]string) - err := filepath.Walk(dir, func(walkPath string, info os.FileInfo, err error) error { + err := filepath.Walk(dir, func(walkPath string, info os.FileInfo, _ error) error { // multi level directory is not allowed under the cmdPath directory, so it is judged that the path ends with cmdPath. if strings.HasSuffix(walkPath, "cmd") { paths, err := os.ReadDir(walkPath) diff --git a/config/config_test.go b/config/config_test.go index ab234dd4863..ec7fc9f7f76 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -154,8 +154,7 @@ func TestConfig(t *testing.T) { t.Fatal("databaseDriver is not equal to val") } - err = cf.Watch("endpoints", func(key string, value Value) { - }) + err = cf.Watch("endpoints", func(string, Value) {}) if err != nil { t.Fatal(err) } diff --git a/config/env/env.go b/config/env/env.go index cdd30e1b70e..ecd5c6ffa8d 100644 --- a/config/env/env.go +++ b/config/env/env.go @@ -23,7 +23,7 @@ func (e *env) load(envs []string) []*config.KeyValue { var kv []*config.KeyValue for _, env := range envs { var k, v string - subs := strings.SplitN(env, "=", 2) //nolint:gomnd + subs := strings.SplitN(env, "=", 2) //nolint:mnd k = subs[0] if len(subs) > 1 { v = subs[1] diff --git a/config/options.go b/config/options.go index 95d6f6d31d9..7395660d5ba 100644 --- a/config/options.go +++ b/config/options.go @@ -137,7 +137,7 @@ func resolver(input map[string]interface{}, mapper func(name string) string, toT func mapper(input map[string]interface{}) func(name string) string { mapper := func(name string) string { - args := strings.SplitN(strings.TrimSpace(name), ":", 2) //nolint:gomnd + args := strings.SplitN(strings.TrimSpace(name), ":", 2) //nolint:mnd if v, has := readValue(input, args[0]); has { s, _ := v.String() return s @@ -183,7 +183,7 @@ func expand(s string, mapping func(string) string, toType bool) interface{} { re := r.FindAllStringSubmatch(s, -1) var ct interface{} for _, i := range re { - if len(i) == 2 { //nolint:gomnd + if len(i) == 2 { //nolint:mnd m := mapping(i[1]) if toType { ct = convertToType(m) diff --git a/config/options_test.go b/config/options_test.go index 83f62b85901..348471d3f70 100644 --- a/config/options_test.go +++ b/config/options_test.go @@ -387,7 +387,7 @@ func TestExpand(t *testing.T) { func TestWithMergeFunc(t *testing.T) { c := &options{} - a := func(dst, src interface{}) error { + a := func(any, any) error { return nil } WithMergeFunc(a)(c) diff --git a/contrib/config/nacos/config_test.go b/contrib/config/nacos/config_test.go index 2d290803795..1667e99dfcc 100644 --- a/contrib/config/nacos/config_test.go +++ b/contrib/config/nacos/config_test.go @@ -166,13 +166,13 @@ func TestConfig_Watch(t *testing.T) { source: source, }, wantErr: false, - processFunc: func(t *testing.T, w config.Watcher) { + processFunc: func(t *testing.T, _ config.Watcher) { _, pErr := client.PublishConfig(vo.ConfigParam{DataId: "test.yaml", Group: "test", Content: "test: test"}) if pErr != nil { t.Error(pErr) } }, - deferFunc: func(t *testing.T, w config.Watcher) { + deferFunc: func(t *testing.T, _ config.Watcher) { _, dErr := client.DeleteConfig(vo.ConfigParam{DataId: "test.yaml", Group: "test"}) if dErr != nil { t.Error(dErr) diff --git a/contrib/opensergo/opensergo_test.go b/contrib/opensergo/opensergo_test.go index 0a2165fb602..322c2c7e36c 100644 --- a/contrib/opensergo/opensergo_test.go +++ b/contrib/opensergo/opensergo_test.go @@ -309,7 +309,7 @@ func TestOpenSergo(t *testing.T) { args: args{ opts: []Option{}, }, - preFunc: func(t *testing.T) { + preFunc: func(_ *testing.T) { err := os.Setenv("OPENSERGO_ENDPOINT", "127.0.0.1:9090") if err != nil { panic(err) @@ -322,7 +322,7 @@ func TestOpenSergo(t *testing.T) { args: args{ opts: []Option{}, }, - preFunc: func(t *testing.T) { + preFunc: func(_ *testing.T) { err := os.Setenv("OPENSERGO_BOOTSTRAP", `{"endpoint": "127.0.0.1:9090"}`) if err != nil { panic(err) diff --git a/contrib/polaris/router.go b/contrib/polaris/router.go index 2478b58b823..93202eb5dad 100644 --- a/contrib/polaris/router.go +++ b/contrib/polaris/router.go @@ -139,7 +139,7 @@ func buildPolarisInstance(namespace string, nodes []selector.Node) *pb.ServiceIn Service: &v1.Service{Name: wrapperspb.String(nodes[0].ServiceName()), Namespace: wrapperspb.String("default")}, Instances: ins, } - return pb.NewServiceInstancesInProto(d, func(s string) local.InstanceLocalValue { + return pb.NewServiceInstancesInProto(d, func(string) local.InstanceLocalValue { return local.NewInstanceLocalValue() }, &pb.SvcPluginValues{Routers: nil, Loadbalancer: nil}, nil) } diff --git a/contrib/registry/consul/registry_test.go b/contrib/registry/consul/registry_test.go index d6799b693ce..9adc89ecaee 100644 --- a/contrib/registry/consul/registry_test.go +++ b/contrib/registry/consul/registry_test.go @@ -329,8 +329,7 @@ func TestRegistry_Watch(t *testing.T) { }, want: []*registry.ServiceInstance{instance1}, wantErr: false, - preFunc: func(t *testing.T) { - }, + preFunc: func(*testing.T) {}, }, { name: "ctx has been canceled", @@ -344,8 +343,7 @@ func TestRegistry_Watch(t *testing.T) { }, want: nil, wantErr: true, - preFunc: func(t *testing.T) { - }, + preFunc: func(*testing.T) {}, }, { name: "register with healthCheck", diff --git a/contrib/registry/etcd/registry.go b/contrib/registry/etcd/registry.go index 476436e2ee6..1a931153fe9 100644 --- a/contrib/registry/etcd/registry.go +++ b/contrib/registry/etcd/registry.go @@ -162,7 +162,7 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key if err != nil { curLeaseID = 0 } - rand.Seed(time.Now().Unix()) + randSource := rand.New(rand.NewSource(time.Now().Unix())) for { if curLeaseID == 0 { @@ -200,7 +200,7 @@ func (r *Registry) heartBeat(ctx context.Context, leaseID clientv3.LeaseID, key break } retreat = append(retreat, 1< Date: Mon, 2 Sep 2024 11:38:28 +0800 Subject: [PATCH 2/2] fix lint --- contrib/registry/kubernetes/registry_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/registry/kubernetes/registry_test.go b/contrib/registry/kubernetes/registry_test.go index 2363b1c3a5e..6f9761a455d 100644 --- a/contrib/registry/kubernetes/registry_test.go +++ b/contrib/registry/kubernetes/registry_test.go @@ -110,7 +110,6 @@ func TestRegistry(t *testing.T) { Endpoints: []string{"http://127.0.0.1:80"}, } _, err = clientSet.AppsV1().Deployments(namespace).Create(context.Background(), &deployment, metav1.CreateOptions{}) - if err != nil { t.Fatal(err) }