fix: rectification of non-standard lint codes (#2746)

pull/2757/head
jessetang 2 years ago committed by GitHub
parent 0c2d2632ac
commit 9a973d29c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      api/metadata/server.go
  2. 4
      app_test.go
  3. 2
      cmd/kratos/internal/change/change.go
  4. 2
      cmd/kratos/internal/project/project.go
  5. 2
      cmd/kratos/internal/proto/add/add.go
  6. 2
      cmd/kratos/internal/proto/client/client.go
  7. 2
      cmd/kratos/internal/proto/server/server.go
  8. 2
      cmd/kratos/internal/upgrade/upgrade.go
  9. 2
      cmd/protoc-gen-go-errors/errors.go
  10. 2
      cmd/protoc-gen-go-http/http.go
  11. 2
      config/options.go
  12. 19
      contrib/config/apollo/apollo.go
  13. 2
      contrib/config/apollo/watcher.go
  14. 2
      contrib/config/consul/watcher.go
  15. 2
      contrib/log/aliyun/aliyun_test.go
  16. 4
      contrib/metrics/datadog/gauge.go
  17. 2
      contrib/opensergo/opensergo_test.go
  18. 2
      contrib/registry/discovery/discovery.go
  19. 2
      contrib/registry/discovery/impl_registrar.go
  20. 4
      contrib/registry/eureka/register_test.go
  21. 4
      contrib/registry/kubernetes/registry.go
  22. 16
      contrib/registry/servicecomb/registry_test.go
  23. 4
      contrib/registry/zookeeper/register.go
  24. 4
      encoding/encoding_test.go
  25. 12
      log/filter_test.go
  26. 8
      log/helper_test.go
  27. 5
      log/log.go
  28. 4
      log/log_test.go
  29. 2
      log/std_test.go
  30. 2
      middleware/circuitbreaker/circuitbreaker_test.go
  31. 4
      middleware/metrics/metrics_test.go
  32. 2
      middleware/ratelimit/ratelimit_test.go
  33. 4
      middleware/tracing/span_test.go
  34. 6
      middleware/tracing/statsHandler.go
  35. 4
      middleware/tracing/statsHandler_test.go
  36. 2
      middleware/tracing/tracer.go
  37. 4
      middleware/tracing/tracer_test.go
  38. 8
      options_test.go
  39. 2
      selector/p2c/p2c.go
  40. 4
      selector/selector_test.go
  41. 2
      transport/grpc/client.go
  42. 4
      transport/grpc/client_test.go
  43. 2
      transport/grpc/resolver/direct/builder.go
  44. 6
      transport/grpc/resolver/direct/builder_test.go
  45. 2
      transport/grpc/resolver/direct/resolver.go
  46. 2
      transport/grpc/resolver/discovery/builder.go
  47. 10
      transport/grpc/resolver/discovery/builder_test.go
  48. 2
      transport/grpc/resolver/discovery/resolver.go
  49. 4
      transport/grpc/server.go
  50. 2
      transport/grpc/server_test.go
  51. 2
      transport/http/calloption.go
  52. 6
      transport/http/client.go
  53. 13
      transport/http/client_test.go
  54. 4
      transport/http/resolver_test.go
  55. 2
      transport/http/router_test.go
  56. 2
      transport/http/server.go
  57. 4
      transport/http/server_test.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 {

@ -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 {

@ -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"

@ -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)

@ -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

@ -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

@ -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

@ -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",

@ -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 {

@ -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)

@ -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) {}
}

@ -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
}

@ -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)

@ -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
}

@ -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()

@ -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) {
}

@ -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
}

@ -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()

@ -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)
}

@ -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 := &registry.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
}

@ -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, &registry.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,
}))

@ -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
}

@ -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)

@ -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")
}

@ -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")

@ -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(),
)

@ -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.

@ -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)
}

@ -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)

@ -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
}

@ -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
}

@ -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
}

@ -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")

@ -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
}

@ -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{}

@ -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 {

@ -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()
})

@ -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
}

@ -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
}

@ -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
}

@ -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) {}
}

@ -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
}

@ -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})

@ -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
}

@ -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) {
}

@ -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

@ -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
}

@ -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 {

@ -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()
}

@ -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))
}

@ -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
}

@ -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
}

@ -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
}

@ -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
}

@ -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

@ -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) {}
}

@ -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) {

Loading…
Cancel
Save