diff --git a/api/metadata/server.go b/api/metadata/server.go index b1c4c17b2..e3d5e373a 100644 --- a/api/metadata/server.go +++ b/api/metadata/server.go @@ -98,7 +98,7 @@ func (s *Server) load() error { } // ListServices return all services -func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*ListServicesReply, error) { +func (s *Server) ListServices(_ context.Context, _ *ListServicesRequest) (*ListServicesReply, error) { s.lock.Lock() defer s.lock.Unlock() if err := s.load(); err != nil { @@ -122,7 +122,7 @@ func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*Li } // GetServiceDesc return service meta by name -func (s *Server) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) { +func (s *Server) GetServiceDesc(_ context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) { s.lock.Lock() defer s.lock.Unlock() if err := s.load(); err != nil { diff --git a/app_test.go b/app_test.go index 92a2ca29f..05e10134b 100644 --- a/app_test.go +++ b/app_test.go @@ -19,7 +19,7 @@ type mockRegistry struct { service map[string]*registry.ServiceInstance } -func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceInstance) error { +func (r *mockRegistry) Register(_ context.Context, service *registry.ServiceInstance) error { if service == nil || service.ID == "" { return errors.New("no service id") } @@ -30,7 +30,7 @@ func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceIn } // Deregister the registration. -func (r *mockRegistry) Deregister(ctx context.Context, service *registry.ServiceInstance) error { +func (r *mockRegistry) Deregister(_ context.Context, service *registry.ServiceInstance) error { r.lk.Lock() defer r.lk.Unlock() if r.service[service.ID] == nil { diff --git a/cmd/kratos/internal/change/change.go b/cmd/kratos/internal/change/change.go index 9327a1796..2e92bee0c 100644 --- a/cmd/kratos/internal/change/change.go +++ b/cmd/kratos/internal/change/change.go @@ -28,7 +28,7 @@ func init() { token = os.Getenv("GITHUB_TOKEN") } -func run(cmd *cobra.Command, args []string) { +func run(_ *cobra.Command, args []string) { owner, repo := ParseGithubURL(repoURL) api := GithubAPI{Owner: owner, Repo: repo, Token: token} version := "latest" diff --git a/cmd/kratos/internal/project/project.go b/cmd/kratos/internal/project/project.go index ce0e1ed42..f1f2cea0c 100644 --- a/cmd/kratos/internal/project/project.go +++ b/cmd/kratos/internal/project/project.go @@ -42,7 +42,7 @@ func init() { CmdNew.Flags().BoolVarP(&nomod, "nomod", "", nomod, "retain go mod") } -func run(cmd *cobra.Command, args []string) { +func run(_ *cobra.Command, args []string) { wd, err := os.Getwd() if err != nil { panic(err) diff --git a/cmd/kratos/internal/proto/add/add.go b/cmd/kratos/internal/proto/add/add.go index e770dd5fb..2415ab9d3 100644 --- a/cmd/kratos/internal/proto/add/add.go +++ b/cmd/kratos/internal/proto/add/add.go @@ -19,7 +19,7 @@ var CmdAdd = &cobra.Command{ Run: run, } -func run(cmd *cobra.Command, args []string) { +func run(_ *cobra.Command, args []string) { if len(args) == 0 { fmt.Println("Please enter the proto file or directory") return diff --git a/cmd/kratos/internal/proto/client/client.go b/cmd/kratos/internal/proto/client/client.go index 013f9f72a..cb3f4a76d 100644 --- a/cmd/kratos/internal/proto/client/client.go +++ b/cmd/kratos/internal/proto/client/client.go @@ -30,7 +30,7 @@ func init() { CmdClient.Flags().StringVarP(&protoPath, "proto_path", "p", protoPath, "proto path") } -func run(cmd *cobra.Command, args []string) { +func run(_ *cobra.Command, args []string) { if len(args) == 0 { fmt.Println("Please enter the proto file or directory") return diff --git a/cmd/kratos/internal/proto/server/server.go b/cmd/kratos/internal/proto/server/server.go index e9af0c716..41fb9ee74 100644 --- a/cmd/kratos/internal/proto/server/server.go +++ b/cmd/kratos/internal/proto/server/server.go @@ -26,7 +26,7 @@ func init() { CmdServer.Flags().StringVarP(&targetDir, "target-dir", "t", "internal/service", "generate target directory") } -func run(cmd *cobra.Command, args []string) { +func run(_ *cobra.Command, args []string) { if len(args) == 0 { fmt.Fprintln(os.Stderr, "Please specify the proto file. Example: kratos proto server api/xxx.proto") return diff --git a/cmd/kratos/internal/upgrade/upgrade.go b/cmd/kratos/internal/upgrade/upgrade.go index 79e53e3cf..20e368da6 100644 --- a/cmd/kratos/internal/upgrade/upgrade.go +++ b/cmd/kratos/internal/upgrade/upgrade.go @@ -17,7 +17,7 @@ var CmdUpgrade = &cobra.Command{ } // Run upgrade the kratos tools. -func Run(cmd *cobra.Command, args []string) { +func Run(_ *cobra.Command, _ []string) { err := base.GoInstall( "github.com/go-kratos/kratos/cmd/kratos/v2@latest", "github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest", diff --git a/cmd/protoc-gen-go-errors/errors.go b/cmd/protoc-gen-go-errors/errors.go index 522c29685..f09c89ea8 100644 --- a/cmd/protoc-gen-go-errors/errors.go +++ b/cmd/protoc-gen-go-errors/errors.go @@ -59,7 +59,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. } } -func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool { +func genErrorsReason(_ *protogen.Plugin, _ *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool { defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode) code := 0 if ok := defaultCode.(int32); ok != 0 { diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index 7a4ff7126..8d799a3be 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -63,7 +63,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. } } -func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) { +func genService(_ *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) { if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") g.P(deprecationComment) diff --git a/config/options.go b/config/options.go index e89a6fcad..443ddaba1 100644 --- a/config/options.go +++ b/config/options.go @@ -51,7 +51,7 @@ func WithResolver(r Resolver) Option { // WithLogger with config logger. // Deprecated: use global logger instead. -func WithLogger(l log.Logger) Option { +func WithLogger(_ log.Logger) Option { return func(o *options) {} } diff --git a/contrib/config/apollo/apollo.go b/contrib/config/apollo/apollo.go index d463df29e..1734fdb02 100644 --- a/contrib/config/apollo/apollo.go +++ b/contrib/config/apollo/apollo.go @@ -5,7 +5,7 @@ import ( "github.com/apolloconfig/agollo/v4" "github.com/apolloconfig/agollo/v4/constant" - apolloConfig "github.com/apolloconfig/agollo/v4/env/config" + apolloconfig "github.com/apolloconfig/agollo/v4/env/config" "github.com/apolloconfig/agollo/v4/extension" "github.com/go-kratos/kratos/v2/config" @@ -112,8 +112,8 @@ func NewSource(opts ...Option) config.Source { for _, o := range opts { o(&op) } - client, err := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) { - return &apolloConfig.AppConfig{ + client, err := agollo.StartWithConfig(func() (*apolloconfig.AppConfig, error) { + return &apolloconfig.AppConfig{ AppID: op.appid, Cluster: op.cluster, NamespaceName: op.namespace, @@ -166,14 +166,13 @@ func (e *apollo) load() []*config.KeyValue { } kvs = append(kvs, kv) continue - } else { - kv, err := e.getConfig(ns) - if err != nil { - log.Errorf("apollo get config failed,err:%v", err) - continue - } - kvs = append(kvs, kv) } + kv, err := e.getConfig(ns) + if err != nil { + log.Errorf("apollo get config failed,err:%v", err) + continue + } + kvs = append(kvs, kv) } return kvs } diff --git a/contrib/config/apollo/watcher.go b/contrib/config/apollo/watcher.go index d59bdd212..ad8424209 100644 --- a/contrib/config/apollo/watcher.go +++ b/contrib/config/apollo/watcher.go @@ -72,7 +72,7 @@ func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) { c.in <- change } -func (c *customChangeListener) OnNewestChange(changeEvent *storage.FullChangeEvent) {} +func (c *customChangeListener) OnNewestChange(_ *storage.FullChangeEvent) {} func newWatcher(a *apollo) (config.Watcher, error) { changeCh := make(chan []*config.KeyValue) diff --git a/contrib/config/consul/watcher.go b/contrib/config/consul/watcher.go index 5c70d6f85..5562505c2 100644 --- a/contrib/config/consul/watcher.go +++ b/contrib/config/consul/watcher.go @@ -18,7 +18,7 @@ type watcher struct { cancel context.CancelFunc } -func (w *watcher) handle(idx uint64, data interface{}) { +func (w *watcher) handle(_ uint64, data interface{}) { if data == nil { return } diff --git a/contrib/log/aliyun/aliyun_test.go b/contrib/log/aliyun/aliyun_test.go index e3e224ad4..d8c914bad 100644 --- a/contrib/log/aliyun/aliyun_test.go +++ b/contrib/log/aliyun/aliyun_test.go @@ -58,7 +58,7 @@ func TestWithAccessSecret(t *testing.T) { } } -func TestLogger(t *testing.T) { +func TestLogger(_ *testing.T) { project := "foo" logger := NewAliyunLog(WithProject(project)) defer logger.Close() diff --git a/contrib/metrics/datadog/gauge.go b/contrib/metrics/datadog/gauge.go index fbff772be..86912f92c 100644 --- a/contrib/metrics/datadog/gauge.go +++ b/contrib/metrics/datadog/gauge.go @@ -39,8 +39,8 @@ func (d *gauge) Set(value float64) { _ = d.opts.client.Gauge(d.name, value, d.lvs, d.opts.sampleRate) } -func (d *gauge) Add(delta float64) { +func (d *gauge) Add(_ float64) { } -func (d *gauge) Sub(delta float64) { +func (d *gauge) Sub(_ float64) { } diff --git a/contrib/opensergo/opensergo_test.go b/contrib/opensergo/opensergo_test.go index 70ffef8fc..0a2165fb6 100644 --- a/contrib/opensergo/opensergo_test.go +++ b/contrib/opensergo/opensergo_test.go @@ -23,7 +23,7 @@ type testMetadataServiceServer struct { srvContractPb.UnimplementedMetadataServiceServer } -func (m *testMetadataServiceServer) ReportMetadata(ctx context.Context, req *srvContractPb.ReportMetadataRequest) (*srvContractPb.ReportMetadataReply, error) { +func (m *testMetadataServiceServer) ReportMetadata(_ context.Context, _ *srvContractPb.ReportMetadataRequest) (*srvContractPb.ReportMetadataReply, error) { return &srvContractPb.ReportMetadataReply{}, nil } diff --git a/contrib/registry/discovery/discovery.go b/contrib/registry/discovery/discovery.go index f439b0cab..bbacd7bb8 100644 --- a/contrib/registry/discovery/discovery.go +++ b/contrib/registry/discovery/discovery.go @@ -427,7 +427,7 @@ func (r *Resolve) Watch() <-chan struct{} { } // fetch resolver instance. -func (r *Resolve) fetch(ctx context.Context) (ins *disInstancesInfo, ok bool) { +func (r *Resolve) fetch(_ context.Context) (ins *disInstancesInfo, ok bool) { r.d.mutex.RLock() app, ok := r.d.apps[r.id] r.d.mutex.RUnlock() diff --git a/contrib/registry/discovery/impl_registrar.go b/contrib/registry/discovery/impl_registrar.go index bb580cc14..c4af66b7b 100644 --- a/contrib/registry/discovery/impl_registrar.go +++ b/contrib/registry/discovery/impl_registrar.go @@ -122,7 +122,7 @@ func (d *Discovery) register(ctx context.Context, ins *discoveryInstance) (err e return } -func (d *Discovery) Deregister(ctx context.Context, service *registry.ServiceInstance) error { +func (d *Discovery) Deregister(_ context.Context, service *registry.ServiceInstance) error { ins := fromServerInstance(service, d.config) return d.cancel(ins) } diff --git a/contrib/registry/eureka/register_test.go b/contrib/registry/eureka/register_test.go index 683b0c587..c8c340c85 100644 --- a/contrib/registry/eureka/register_test.go +++ b/contrib/registry/eureka/register_test.go @@ -11,7 +11,7 @@ import ( "github.com/go-kratos/kratos/v2/registry" ) -func TestRegistry(t *testing.T) { +func TestRegistry(_ *testing.T) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) s1 := ®istry.ServiceInstance{ @@ -92,7 +92,7 @@ func do(r *Registry, s *registry.ServiceInstance) { } } -func TestLock(t *testing.T) { +func TestLock(_ *testing.T) { type me struct { lock sync.Mutex } diff --git a/contrib/registry/kubernetes/registry.go b/contrib/registry/kubernetes/registry.go index 987ef1e1e..21562dc55 100644 --- a/contrib/registry/kubernetes/registry.go +++ b/contrib/registry/kubernetes/registry.go @@ -151,14 +151,14 @@ func (s *Registry) Register(ctx context.Context, service *registry.ServiceInstan } // Deregister the registration. -func (s *Registry) Deregister(ctx context.Context, service *registry.ServiceInstance) error { +func (s *Registry) Deregister(ctx context.Context, _ *registry.ServiceInstance) error { return s.Register(ctx, ®istry.ServiceInstance{ Metadata: map[string]string{}, }) } // GetService return the service instances in memory according to the service name. -func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error) { +func (s *Registry) GetService(_ context.Context, name string) ([]*registry.ServiceInstance, error) { pods, err := s.podLister.List(labels.SelectorFromSet(map[string]string{ LabelsKeyServiceName: name, })) diff --git a/contrib/registry/servicecomb/registry_test.go b/contrib/registry/servicecomb/registry_test.go index 4b4c25490..9e1394925 100644 --- a/contrib/registry/servicecomb/registry_test.go +++ b/contrib/registry/servicecomb/registry_test.go @@ -19,13 +19,13 @@ func init() { type mockClient struct{} -func (receiver *mockClient) WatchMicroService(microServiceID string, callback func(*sc.MicroServiceInstanceChangedEvent)) error { +func (receiver *mockClient) WatchMicroService(_ string, _ func(*sc.MicroServiceInstanceChangedEvent)) error { return nil } //nolint -func (receiver *mockClient) FindMicroServiceInstances(consumerID, - appID, microServiceName, versionRule string, opts ...sc.CallOption, +func (receiver *mockClient) FindMicroServiceInstances(_, + _, microServiceName, _ string, _ ...sc.CallOption, ) ([]*pb.MicroServiceInstance, error) { if microServiceName == "KratosServicecomb" { return []*pb.MicroServiceInstance{{}}, nil @@ -33,23 +33,23 @@ func (receiver *mockClient) FindMicroServiceInstances(consumerID, return nil, nil } -func (receiver *mockClient) RegisterService(microService *pb.MicroService) (string, error) { +func (receiver *mockClient) RegisterService(_ *pb.MicroService) (string, error) { return "", nil } -func (receiver *mockClient) RegisterMicroServiceInstance(microServiceInstance *pb.MicroServiceInstance) (string, error) { +func (receiver *mockClient) RegisterMicroServiceInstance(_ *pb.MicroServiceInstance) (string, error) { return "", nil } -func (receiver *mockClient) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error) { +func (receiver *mockClient) Heartbeat(_, _ string) (bool, error) { return true, nil } -func (receiver *mockClient) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error) { +func (receiver *mockClient) UnregisterMicroServiceInstance(_, _ string) (bool, error) { return true, nil } -func (receiver *mockClient) GetMicroServiceID(appID, microServiceName, version, env string, opts ...sc.CallOption) (string, error) { +func (receiver *mockClient) GetMicroServiceID(_, _, _, _ string, _ ...sc.CallOption) (string, error) { return "", nil } diff --git a/contrib/registry/zookeeper/register.go b/contrib/registry/zookeeper/register.go index 8f21745d1..0e4ff0bb1 100644 --- a/contrib/registry/zookeeper/register.go +++ b/contrib/registry/zookeeper/register.go @@ -59,7 +59,7 @@ func New(conn *zk.Conn, opts ...Option) *Registry { } } -func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error { +func (r *Registry) Register(_ context.Context, service *registry.ServiceInstance) error { var ( data []byte err error @@ -100,7 +100,7 @@ func (r *Registry) Deregister(ctx context.Context, service *registry.ServiceInst } // GetService get services from zookeeper -func (r *Registry) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) { +func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error) { instances, err, _ := r.group.Do(serviceName, func() (interface{}, error) { serviceNamePath := path.Join(r.opts.namespace, serviceName) servicesID, _, err := r.conn.Children(serviceNamePath) diff --git a/encoding/encoding_test.go b/encoding/encoding_test.go index 1d79ebbd0..9746788ab 100644 --- a/encoding/encoding_test.go +++ b/encoding/encoding_test.go @@ -9,11 +9,11 @@ import ( type codec struct{} -func (c codec) Marshal(v interface{}) ([]byte, error) { +func (c codec) Marshal(_ interface{}) ([]byte, error) { panic("implement me") } -func (c codec) Unmarshal(data []byte, v interface{}) error { +func (c codec) Unmarshal(_ []byte, _ interface{}) error { panic("implement me") } diff --git a/log/filter_test.go b/log/filter_test.go index 3e36deac1..9258400c3 100644 --- a/log/filter_test.go +++ b/log/filter_test.go @@ -6,7 +6,7 @@ import ( "testing" ) -func TestFilterAll(t *testing.T) { +func TestFilterAll(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(NewFilter(logger, FilterLevel(LevelDebug), @@ -21,7 +21,7 @@ func TestFilterAll(t *testing.T) { log.Warn("warn log") } -func TestFilterLevel(t *testing.T) { +func TestFilterLevel(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(NewFilter(NewFilter(logger, FilterLevel(LevelWarn)))) log.Log(LevelDebug, "msg1", "te1st debug") @@ -31,7 +31,7 @@ func TestFilterLevel(t *testing.T) { log.Warn("warn log") } -func TestFilterCaller(t *testing.T) { +func TestFilterCaller(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewFilter(logger) _ = log.Log(LevelDebug, "msg1", "te1st debug") @@ -39,19 +39,19 @@ func TestFilterCaller(t *testing.T) { logHelper.Log(LevelDebug, "msg1", "te1st debug") } -func TestFilterKey(t *testing.T) { +func TestFilterKey(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(NewFilter(logger, FilterKey("password"))) log.Debugw("password", "123456") } -func TestFilterValue(t *testing.T) { +func TestFilterValue(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(NewFilter(logger, FilterValue("debug"))) log.Debugf("test %s", "debug") } -func TestFilterFunc(t *testing.T) { +func TestFilterFunc(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(NewFilter(logger, FilterFunc(testFilterFunc))) log.Debug("debug level") diff --git a/log/helper_test.go b/log/helper_test.go index 0cb4ba87f..c52f338b2 100644 --- a/log/helper_test.go +++ b/log/helper_test.go @@ -7,7 +7,7 @@ import ( "testing" ) -func TestHelper(t *testing.T) { +func TestHelper(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(logger) @@ -21,14 +21,14 @@ func TestHelper(t *testing.T) { log.Warnw("log", "test warn") } -func TestHelperWithMsgKey(t *testing.T) { +func TestHelperWithMsgKey(_ *testing.T) { logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller) log := NewHelper(logger, WithMessageKey("message")) log.Debugf("test %s", "debug") log.Debugw("log", "test debug") } -func TestHelperLevel(t *testing.T) { +func TestHelperLevel(_ *testing.T) { log := NewHelper(DefaultLogger) log.Debug("test debug") log.Info("test info") @@ -62,7 +62,7 @@ func BenchmarkHelperPrintw(b *testing.B) { type traceKey struct{} -func TestContext(t *testing.T) { +func TestContext(_ *testing.T) { logger := With(NewStdLogger(os.Stdout), "trace", Trace(), ) diff --git a/log/log.go b/log/log.go index bbaf94dae..5022ba4bb 100644 --- a/log/log.go +++ b/log/log.go @@ -27,10 +27,7 @@ func (c *logger) Log(level Level, keyvals ...interface{}) error { bindValues(c.ctx, kvs) } kvs = append(kvs, keyvals...) - if err := c.logger.Log(level, kvs...); err != nil { - return err - } - return nil + return c.logger.Log(level, kvs...) } // With with logger fields. diff --git a/log/log_test.go b/log/log_test.go index 38417f76d..8221d9ef5 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -5,13 +5,13 @@ import ( "testing" ) -func TestInfo(t *testing.T) { +func TestInfo(_ *testing.T) { logger := DefaultLogger logger = With(logger, "ts", DefaultTimestamp) logger = With(logger, "caller", DefaultCaller) _ = logger.Log(LevelInfo, "key1", "value1") } -func TestWithContext(t *testing.T) { +func TestWithContext(_ *testing.T) { WithContext(context.Background(), nil) } diff --git a/log/std_test.go b/log/std_test.go index e9da7730a..2518a0467 100644 --- a/log/std_test.go +++ b/log/std_test.go @@ -2,7 +2,7 @@ package log import "testing" -func TestStdLogger(t *testing.T) { +func TestStdLogger(_ *testing.T) { logger := DefaultLogger logger = With(logger, "caller", DefaultCaller, "ts", DefaultTimestamp) diff --git a/middleware/circuitbreaker/circuitbreaker_test.go b/middleware/circuitbreaker/circuitbreaker_test.go index 611419c78..3b27da1a3 100644 --- a/middleware/circuitbreaker/circuitbreaker_test.go +++ b/middleware/circuitbreaker/circuitbreaker_test.go @@ -57,7 +57,7 @@ func Test_WithGroup(t *testing.T) { } } -func Test_Server(t *testing.T) { +func TestServer(_ *testing.T) { nextValid := func(ctx context.Context, req interface{}) (interface{}, error) { return "Hello valid", nil } diff --git a/middleware/metrics/metrics_test.go b/middleware/metrics/metrics_test.go index 9cf261cee..72b3137d9 100644 --- a/middleware/metrics/metrics_test.go +++ b/middleware/metrics/metrics_test.go @@ -21,7 +21,7 @@ type ( } ) -func (m *mockCounter) With(lvs ...string) metrics.Counter { +func (m *mockCounter) With(_ ...string) metrics.Counter { return m } @@ -33,7 +33,7 @@ func (m *mockCounter) Add(delta float64) { m.value += delta } -func (m *mockObserver) With(lvs ...string) metrics.Observer { +func (m *mockObserver) With(_ ...string) metrics.Observer { return m } diff --git a/middleware/ratelimit/ratelimit_test.go b/middleware/ratelimit/ratelimit_test.go index 2e4e5bde3..b1422347e 100644 --- a/middleware/ratelimit/ratelimit_test.go +++ b/middleware/ratelimit/ratelimit_test.go @@ -40,7 +40,7 @@ func Test_WithLimiter(t *testing.T) { } } -func Test_Server(t *testing.T) { +func TestServer(t *testing.T) { nextValid := func(ctx context.Context, req interface{}) (interface{}, error) { return "Hello valid", nil } diff --git a/middleware/tracing/span_test.go b/middleware/tracing/span_test.go index 110dc6f5e..6929ece18 100644 --- a/middleware/tracing/span_test.go +++ b/middleware/tracing/span_test.go @@ -178,7 +178,7 @@ func Test_parseTarget(t *testing.T) { } } -func Test_setServerSpan(t *testing.T) { +func TestSetServerSpan(_ *testing.T) { ctx := context.Background() _, span := trace.NewNoopTracerProvider().Tracer("Tracer").Start(ctx, "Spanname") @@ -211,7 +211,7 @@ func Test_setServerSpan(t *testing.T) { setServerSpan(ctx, span, m) } -func Test_setClientSpan(t *testing.T) { +func TestSetClientSpan(_ *testing.T) { ctx := context.Background() _, span := trace.NewNoopTracerProvider().Tracer("Tracer").Start(ctx, "Spanname") diff --git a/middleware/tracing/statsHandler.go b/middleware/tracing/statsHandler.go index b9ee3fd1e..594be9e12 100644 --- a/middleware/tracing/statsHandler.go +++ b/middleware/tracing/statsHandler.go @@ -13,12 +13,12 @@ import ( type ClientHandler struct{} // HandleConn exists to satisfy gRPC stats.Handler. -func (c *ClientHandler) HandleConn(ctx context.Context, cs stats.ConnStats) { +func (c *ClientHandler) HandleConn(_ context.Context, _ stats.ConnStats) { fmt.Println("Handle connection.") } // TagConn exists to satisfy gRPC stats.Handler. -func (c *ClientHandler) TagConn(ctx context.Context, cti *stats.ConnTagInfo) context.Context { +func (c *ClientHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context { return ctx } @@ -38,6 +38,6 @@ func (c *ClientHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) { } // TagRPC implements per-RPC context management. -func (c *ClientHandler) TagRPC(ctx context.Context, rti *stats.RPCTagInfo) context.Context { +func (c *ClientHandler) TagRPC(ctx context.Context, _ *stats.RPCTagInfo) context.Context { return ctx } diff --git a/middleware/tracing/statsHandler_test.go b/middleware/tracing/statsHandler_test.go index d8a38dcd1..ec7ea06aa 100644 --- a/middleware/tracing/statsHandler_test.go +++ b/middleware/tracing/statsHandler_test.go @@ -14,7 +14,7 @@ type ctxKey string const testKey ctxKey = "MY_TEST_KEY" -func Test_Client_HandleConn(t *testing.T) { +func TestClient_HandleConn(_ *testing.T) { (&ClientHandler{}).HandleConn(context.Background(), nil) } @@ -47,7 +47,7 @@ func (m *mockSpan) SpanContext() trace.SpanContext { return *m.mockSpanCtx } -func Test_Client_HandleRPC(t *testing.T) { +func TestClient_HandleRPC(_ *testing.T) { client := &ClientHandler{} ctx := context.Background() rs := stats.OutHeader{} diff --git a/middleware/tracing/tracer.go b/middleware/tracing/tracer.go index 798994f87..b4455309f 100644 --- a/middleware/tracing/tracer.go +++ b/middleware/tracing/tracer.go @@ -60,7 +60,7 @@ func (t *Tracer) Start(ctx context.Context, operation string, carrier propagatio } // End finish tracing span -func (t *Tracer) End(ctx context.Context, span trace.Span, m interface{}, err error) { +func (t *Tracer) End(_ context.Context, span trace.Span, m interface{}, err error) { if err != nil { span.RecordError(err) if e := errors.FromError(err); e != nil { diff --git a/middleware/tracing/tracer_test.go b/middleware/tracing/tracer_test.go index af63844e2..8983a0732 100644 --- a/middleware/tracing/tracer_test.go +++ b/middleware/tracing/tracer_test.go @@ -10,7 +10,7 @@ import ( "github.com/go-kratos/kratos/v2/internal/testdata/binding" ) -func Test_NewTracer(t *testing.T) { +func TestNewTracer(t *testing.T) { tracer := NewTracer(trace.SpanKindClient, func(o *options) { o.tracerProvider = trace.NewNoopTracerProvider() }) @@ -29,7 +29,7 @@ func Test_NewTracer(t *testing.T) { }) } -func Test_Tracer_End(t *testing.T) { +func TestTracer_End(_ *testing.T) { tracer := NewTracer(trace.SpanKindClient, func(o *options) { o.tracerProvider = trace.NewNoopTracerProvider() }) diff --git a/options_test.go b/options_test.go index 606001737..e1b7288bd 100644 --- a/options_test.go +++ b/options_test.go @@ -86,8 +86,8 @@ func TestLogger(t *testing.T) { type mockServer struct{} -func (m *mockServer) Start(ctx context.Context) error { return nil } -func (m *mockServer) Stop(ctx context.Context) error { return nil } +func (m *mockServer) Start(_ context.Context) error { return nil } +func (m *mockServer) Stop(_ context.Context) error { return nil } func TestServer(t *testing.T) { o := &options{} @@ -118,11 +118,11 @@ func TestSignal(t *testing.T) { type mockRegistrar struct{} -func (m *mockRegistrar) Register(ctx context.Context, service *registry.ServiceInstance) error { +func (m *mockRegistrar) Register(_ context.Context, _ *registry.ServiceInstance) error { return nil } -func (m *mockRegistrar) Deregister(ctx context.Context, service *registry.ServiceInstance) error { +func (m *mockRegistrar) Deregister(_ context.Context, _ *registry.ServiceInstance) error { return nil } diff --git a/selector/p2c/p2c.go b/selector/p2c/p2c.go index 5e339b0c2..1d0ef8c56 100644 --- a/selector/p2c/p2c.go +++ b/selector/p2c/p2c.go @@ -51,7 +51,7 @@ func (s *Balancer) prePick(nodes []selector.WeightedNode) (nodeA selector.Weight } // Pick pick a node. -func (s *Balancer) Pick(ctx context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) { +func (s *Balancer) Pick(_ context.Context, nodes []selector.WeightedNode) (selector.WeightedNode, selector.DoneFunc, error) { if len(nodes) == 0 { return nil, nil, selector.ErrNoAvailable } diff --git a/selector/selector_test.go b/selector/selector_test.go index ca30fc0a0..b7b963f0c 100644 --- a/selector/selector_test.go +++ b/selector/selector_test.go @@ -71,7 +71,7 @@ func (b *mockBalancerBuilder) Build() Balancer { type mockBalancer struct{} -func (b *mockBalancer) Pick(ctx context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error) { +func (b *mockBalancer) Pick(_ context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error) { if len(nodes) == 0 { err = ErrNoAvailable return @@ -90,7 +90,7 @@ func (b *mockMustErrorBalancerBuilder) Build() Balancer { type mockMustErrorBalancer struct{} -func (b *mockMustErrorBalancer) Pick(ctx context.Context, nodes []WeightedNode) (selected WeightedNode, done DoneFunc, err error) { +func (b *mockMustErrorBalancer) Pick(_ context.Context, _ []WeightedNode) (selected WeightedNode, done DoneFunc, err error) { return nil, nil, errNodeNotMatch } diff --git a/transport/grpc/client.go b/transport/grpc/client.go index 2d614cb07..a7a00910e 100644 --- a/transport/grpc/client.go +++ b/transport/grpc/client.go @@ -105,7 +105,7 @@ func WithNodeFilter(filters ...selector.NodeFilter) ClientOption { // WithLogger with logger // Deprecated: use global logger instead. -func WithLogger(log log.Logger) ClientOption { +func WithLogger(_ log.Logger) ClientOption { return func(o *clientOptions) {} } diff --git a/transport/grpc/client_test.go b/transport/grpc/client_test.go index 7ad553686..b2e5e3776 100644 --- a/transport/grpc/client_test.go +++ b/transport/grpc/client_test.go @@ -44,11 +44,11 @@ func TestWithMiddleware(t *testing.T) { type mockRegistry struct{} -func (m *mockRegistry) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) { +func (m *mockRegistry) GetService(_ context.Context, _ string) ([]*registry.ServiceInstance, error) { return nil, nil } -func (m *mockRegistry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) { +func (m *mockRegistry) Watch(_ context.Context, _ string) (registry.Watcher, error) { return nil, nil } diff --git a/transport/grpc/resolver/direct/builder.go b/transport/grpc/resolver/direct/builder.go index 6035e2d5f..ebbd22d7a 100644 --- a/transport/grpc/resolver/direct/builder.go +++ b/transport/grpc/resolver/direct/builder.go @@ -20,7 +20,7 @@ func NewBuilder() resolver.Builder { return &directBuilder{} } -func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { +func (d *directBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) { addrs := make([]resolver.Address, 0) for _, addr := range strings.Split(strings.TrimPrefix(target.URL.Path, "/"), ",") { addrs = append(addrs, resolver.Address{Addr: addr}) diff --git a/transport/grpc/resolver/direct/builder_test.go b/transport/grpc/resolver/direct/builder_test.go index 82cd8cd1f..d0a347df0 100644 --- a/transport/grpc/resolver/direct/builder_test.go +++ b/transport/grpc/resolver/direct/builder_test.go @@ -29,11 +29,11 @@ func (m *mockConn) UpdateState(resolver.State) error { func (m *mockConn) ReportError(error) {} -func (m *mockConn) NewAddress(addresses []resolver.Address) {} +func (m *mockConn) NewAddress(_ []resolver.Address) {} -func (m *mockConn) NewServiceConfig(serviceConfig string) {} +func (m *mockConn) NewServiceConfig(_ string) {} -func (m *mockConn) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult { +func (m *mockConn) ParseServiceConfig(_ string) *serviceconfig.ParseResult { return nil } diff --git a/transport/grpc/resolver/direct/resolver.go b/transport/grpc/resolver/direct/resolver.go index 7d18228c8..e2dce6187 100644 --- a/transport/grpc/resolver/direct/resolver.go +++ b/transport/grpc/resolver/direct/resolver.go @@ -11,5 +11,5 @@ func newDirectResolver() resolver.Resolver { func (r *directResolver) Close() { } -func (r *directResolver) ResolveNow(options resolver.ResolveNowOptions) { +func (r *directResolver) ResolveNow(_ resolver.ResolveNowOptions) { } diff --git a/transport/grpc/resolver/discovery/builder.go b/transport/grpc/resolver/discovery/builder.go index 37a9b560c..28aff384e 100644 --- a/transport/grpc/resolver/discovery/builder.go +++ b/transport/grpc/resolver/discovery/builder.go @@ -76,7 +76,7 @@ func NewBuilder(d registry.Discovery, opts ...Option) resolver.Builder { return b } -func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) { +func (b *builder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (resolver.Resolver, error) { watchRes := &struct { err error w registry.Watcher diff --git a/transport/grpc/resolver/discovery/builder_test.go b/transport/grpc/resolver/discovery/builder_test.go index 21d5585c0..e216a5445 100644 --- a/transport/grpc/resolver/discovery/builder_test.go +++ b/transport/grpc/resolver/discovery/builder_test.go @@ -40,11 +40,11 @@ func TestDisableDebugLog(t *testing.T) { type mockDiscovery struct{} -func (m *mockDiscovery) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) { +func (m *mockDiscovery) GetService(_ context.Context, _ string) ([]*registry.ServiceInstance, error) { return nil, nil } -func (m *mockDiscovery) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) { +func (m *mockDiscovery) Watch(_ context.Context, _ string) (registry.Watcher, error) { time.Sleep(time.Microsecond * 500) return &testWatch{}, nil } @@ -64,11 +64,11 @@ func (m *mockConn) UpdateState(resolver.State) error { func (m *mockConn) ReportError(error) {} -func (m *mockConn) NewAddress(addresses []resolver.Address) {} +func (m *mockConn) NewAddress(_ []resolver.Address) {} -func (m *mockConn) NewServiceConfig(serviceConfig string) {} +func (m *mockConn) NewServiceConfig(_ string) {} -func (m *mockConn) ParseServiceConfig(serviceConfigJSON string) *serviceconfig.ParseResult { +func (m *mockConn) ParseServiceConfig(_ string) *serviceconfig.ParseResult { return nil } diff --git a/transport/grpc/resolver/discovery/resolver.go b/transport/grpc/resolver/discovery/resolver.go index c50c65cbd..03c76664d 100644 --- a/transport/grpc/resolver/discovery/resolver.go +++ b/transport/grpc/resolver/discovery/resolver.go @@ -104,7 +104,7 @@ func (r *discoveryResolver) Close() { } } -func (r *discoveryResolver) ResolveNow(options resolver.ResolveNowOptions) {} +func (r *discoveryResolver) ResolveNow(_ resolver.ResolveNowOptions) {} func parseAttributes(md map[string]string) (a *attributes.Attributes) { for k, v := range md { diff --git a/transport/grpc/server.go b/transport/grpc/server.go index 4c3deccf9..9a8344bfe 100644 --- a/transport/grpc/server.go +++ b/transport/grpc/server.go @@ -56,7 +56,7 @@ func Timeout(timeout time.Duration) ServerOption { // Logger with server logger. // Deprecated: use global logger instead. -func Logger(logger log.Logger) ServerOption { +func Logger(_ log.Logger) ServerOption { return func(s *Server) {} } @@ -210,7 +210,7 @@ func (s *Server) Start(ctx context.Context) error { } // Stop stop the gRPC server. -func (s *Server) Stop(ctx context.Context) error { +func (s *Server) Stop(_ context.Context) error { if s.adminClean != nil { s.adminClean() } diff --git a/transport/grpc/server_test.go b/transport/grpc/server_test.go index 4db44fe95..d9d2c7af3 100644 --- a/transport/grpc/server_test.go +++ b/transport/grpc/server_test.go @@ -56,7 +56,7 @@ func (s *server) SayHelloStream(streamServer pb.Greeter_SayHelloStreamServer) er } // SayHello implements helloworld.GreeterServer -func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { +func (s *server) SayHello(_ context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { if in.Name == "error" { return nil, errors.BadRequest("custom_error", fmt.Sprintf("invalid argument %s", in.Name)) } diff --git a/transport/http/calloption.go b/transport/http/calloption.go index 7b0ed82d1..e8329410a 100644 --- a/transport/http/calloption.go +++ b/transport/http/calloption.go @@ -102,7 +102,7 @@ type HeaderCallOption struct { header *http.Header } -func (o HeaderCallOption) after(c *callInfo, cs *csAttempt) { +func (o HeaderCallOption) after(_ *callInfo, cs *csAttempt) { if cs.res != nil && cs.res.Header != nil { *o.header = cs.res.Header } diff --git a/transport/http/client.go b/transport/http/client.go index 52ee13509..2d2a352ca 100644 --- a/transport/http/client.go +++ b/transport/http/client.go @@ -327,7 +327,7 @@ func (client *Client) Close() error { } // DefaultRequestEncoder is an HTTP request encoder. -func DefaultRequestEncoder(ctx context.Context, contentType string, in interface{}) ([]byte, error) { +func DefaultRequestEncoder(_ context.Context, contentType string, in interface{}) ([]byte, error) { name := httputil.ContentSubtype(contentType) body, err := encoding.GetCodec(name).Marshal(in) if err != nil { @@ -337,7 +337,7 @@ func DefaultRequestEncoder(ctx context.Context, contentType string, in interface } // DefaultResponseDecoder is an HTTP response decoder. -func DefaultResponseDecoder(ctx context.Context, res *http.Response, v interface{}) error { +func DefaultResponseDecoder(_ context.Context, res *http.Response, v interface{}) error { defer res.Body.Close() data, err := io.ReadAll(res.Body) if err != nil { @@ -347,7 +347,7 @@ func DefaultResponseDecoder(ctx context.Context, res *http.Response, v interface } // DefaultErrorDecoder is an HTTP error decoder. -func DefaultErrorDecoder(ctx context.Context, res *http.Response) error { +func DefaultErrorDecoder(_ context.Context, res *http.Response) error { if res.StatusCode >= 200 && res.StatusCode <= 299 { return nil } diff --git a/transport/http/client_test.go b/transport/http/client_test.go index 119c8c0bf..063878af8 100644 --- a/transport/http/client_test.go +++ b/transport/http/client_test.go @@ -23,7 +23,7 @@ import ( type mockRoundTripper struct{} -func (rt *mockRoundTripper) RoundTrip(req *http.Request) (resp *http.Response, err error) { +func (rt *mockRoundTripper) RoundTrip(_ *http.Request) (resp *http.Response, err error) { return } @@ -31,14 +31,14 @@ type mockCallOption struct { needErr bool } -func (x *mockCallOption) before(info *callInfo) error { +func (x *mockCallOption) before(_ *callInfo) error { if x.needErr { return errors.New("option need return err") } return nil } -func (x *mockCallOption) after(info *callInfo, attempt *csAttempt) { +func (x *mockCallOption) after(_ *callInfo, _ *csAttempt) { log.Println("run in mockCallOption.after") } @@ -71,7 +71,8 @@ func TestWithBlock(t *testing.T) { } } -func TestWithBalancer(t *testing.T) { +func TestWithBalancer(_ *testing.T) { + // TODO } func TestWithTLSConfig(t *testing.T) { @@ -146,11 +147,11 @@ func TestWithErrorDecoder(t *testing.T) { type mockDiscovery struct{} -func (*mockDiscovery) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) { +func (*mockDiscovery) GetService(_ context.Context, _ string) ([]*registry.ServiceInstance, error) { return nil, nil } -func (*mockDiscovery) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) { +func (*mockDiscovery) Watch(_ context.Context, _ string) (registry.Watcher, error) { return &mockWatcher{}, nil } diff --git a/transport/http/resolver_test.go b/transport/http/resolver_test.go index 4dfe3c5c9..e1cfd1033 100644 --- a/transport/http/resolver_test.go +++ b/transport/http/resolver_test.go @@ -57,7 +57,7 @@ func TestParseTarget(t *testing.T) { type mockRebalancer struct{} -func (m *mockRebalancer) Apply(nodes []selector.Node) {} +func (m *mockRebalancer) Apply(_ []selector.Node) {} type mockDiscoveries struct { isSecure bool @@ -65,7 +65,7 @@ type mockDiscoveries struct { stopErr bool } -func (d *mockDiscoveries) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) { +func (d *mockDiscoveries) GetService(_ context.Context, _ string) ([]*registry.ServiceInstance, error) { return nil, nil } diff --git a/transport/http/router_test.go b/transport/http/router_test.go index 747ebf059..1849939d1 100644 --- a/transport/http/router_test.go +++ b/transport/http/router_test.go @@ -179,7 +179,7 @@ func TestRouter_Group(t *testing.T) { } } -func TestHandle(t *testing.T) { +func TestHandle(_ *testing.T) { r := newRouter("/", NewServer()) h := func(i Context) error { return nil diff --git a/transport/http/server.go b/transport/http/server.go index 165bb99bc..7b27d326e 100644 --- a/transport/http/server.go +++ b/transport/http/server.go @@ -52,7 +52,7 @@ func Timeout(timeout time.Duration) ServerOption { // Logger with server logger. // Deprecated: use global logger instead. -func Logger(logger log.Logger) ServerOption { +func Logger(_ log.Logger) ServerOption { return func(s *Server) {} } diff --git a/transport/http/server_test.go b/transport/http/server_test.go index 22865fc33..781c06a71 100644 --- a/transport/http/server_test.go +++ b/transport/http/server_test.go @@ -308,8 +308,8 @@ func TestTimeout(t *testing.T) { } } -func TestLogger(t *testing.T) { - // todo +func TestLogger(_ *testing.T) { + // TODO } func TestRequestDecoder(t *testing.T) {