Skip to content

Commit 9a973d2

Browse files
authored
fix: rectification of non-standard lint codes (go-kratos#2746)
1 parent 0c2d263 commit 9a973d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+116
-119
lines changed

api/metadata/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (s *Server) load() error {
9898
}
9999

100100
// ListServices return all services
101-
func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*ListServicesReply, error) {
101+
func (s *Server) ListServices(_ context.Context, _ *ListServicesRequest) (*ListServicesReply, error) {
102102
s.lock.Lock()
103103
defer s.lock.Unlock()
104104
if err := s.load(); err != nil {
@@ -122,7 +122,7 @@ func (s *Server) ListServices(ctx context.Context, in *ListServicesRequest) (*Li
122122
}
123123

124124
// GetServiceDesc return service meta by name
125-
func (s *Server) GetServiceDesc(ctx context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
125+
func (s *Server) GetServiceDesc(_ context.Context, in *GetServiceDescRequest) (*GetServiceDescReply, error) {
126126
s.lock.Lock()
127127
defer s.lock.Unlock()
128128
if err := s.load(); err != nil {

app_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type mockRegistry struct {
1919
service map[string]*registry.ServiceInstance
2020
}
2121

22-
func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceInstance) error {
22+
func (r *mockRegistry) Register(_ context.Context, service *registry.ServiceInstance) error {
2323
if service == nil || service.ID == "" {
2424
return errors.New("no service id")
2525
}
@@ -30,7 +30,7 @@ func (r *mockRegistry) Register(ctx context.Context, service *registry.ServiceIn
3030
}
3131

3232
// Deregister the registration.
33-
func (r *mockRegistry) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
33+
func (r *mockRegistry) Deregister(_ context.Context, service *registry.ServiceInstance) error {
3434
r.lk.Lock()
3535
defer r.lk.Unlock()
3636
if r.service[service.ID] == nil {

cmd/kratos/internal/change/change.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func init() {
2828
token = os.Getenv("GITHUB_TOKEN")
2929
}
3030

31-
func run(cmd *cobra.Command, args []string) {
31+
func run(_ *cobra.Command, args []string) {
3232
owner, repo := ParseGithubURL(repoURL)
3333
api := GithubAPI{Owner: owner, Repo: repo, Token: token}
3434
version := "latest"

cmd/kratos/internal/project/project.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func init() {
4242
CmdNew.Flags().BoolVarP(&nomod, "nomod", "", nomod, "retain go mod")
4343
}
4444

45-
func run(cmd *cobra.Command, args []string) {
45+
func run(_ *cobra.Command, args []string) {
4646
wd, err := os.Getwd()
4747
if err != nil {
4848
panic(err)

cmd/kratos/internal/proto/add/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var CmdAdd = &cobra.Command{
1919
Run: run,
2020
}
2121

22-
func run(cmd *cobra.Command, args []string) {
22+
func run(_ *cobra.Command, args []string) {
2323
if len(args) == 0 {
2424
fmt.Println("Please enter the proto file or directory")
2525
return

cmd/kratos/internal/proto/client/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func init() {
3030
CmdClient.Flags().StringVarP(&protoPath, "proto_path", "p", protoPath, "proto path")
3131
}
3232

33-
func run(cmd *cobra.Command, args []string) {
33+
func run(_ *cobra.Command, args []string) {
3434
if len(args) == 0 {
3535
fmt.Println("Please enter the proto file or directory")
3636
return

cmd/kratos/internal/proto/server/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func init() {
2626
CmdServer.Flags().StringVarP(&targetDir, "target-dir", "t", "internal/service", "generate target directory")
2727
}
2828

29-
func run(cmd *cobra.Command, args []string) {
29+
func run(_ *cobra.Command, args []string) {
3030
if len(args) == 0 {
3131
fmt.Fprintln(os.Stderr, "Please specify the proto file. Example: kratos proto server api/xxx.proto")
3232
return

cmd/kratos/internal/upgrade/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var CmdUpgrade = &cobra.Command{
1717
}
1818

1919
// Run upgrade the kratos tools.
20-
func Run(cmd *cobra.Command, args []string) {
20+
func Run(_ *cobra.Command, _ []string) {
2121
err := base.GoInstall(
2222
"github.com/go-kratos/kratos/cmd/kratos/v2@latest",
2323
"github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest",

cmd/protoc-gen-go-errors/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
5959
}
6060
}
6161

62-
func genErrorsReason(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
62+
func genErrorsReason(_ *protogen.Plugin, _ *protogen.File, g *protogen.GeneratedFile, enum *protogen.Enum) bool {
6363
defaultCode := proto.GetExtension(enum.Desc.Options(), errors.E_DefaultCode)
6464
code := 0
6565
if ok := defaultCode.(int32); ok != 0 {

cmd/protoc-gen-go-http/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen.
6363
}
6464
}
6565

66-
func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) {
66+
func genService(_ *protogen.Plugin, file *protogen.File, g *protogen.GeneratedFile, service *protogen.Service, omitempty bool) {
6767
if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() {
6868
g.P("//")
6969
g.P(deprecationComment)

config/options.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func WithResolver(r Resolver) Option {
5151

5252
// WithLogger with config logger.
5353
// Deprecated: use global logger instead.
54-
func WithLogger(l log.Logger) Option {
54+
func WithLogger(_ log.Logger) Option {
5555
return func(o *options) {}
5656
}
5757

contrib/config/apollo/apollo.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
"github.com/apolloconfig/agollo/v4"
77
"github.com/apolloconfig/agollo/v4/constant"
8-
apolloConfig "github.com/apolloconfig/agollo/v4/env/config"
8+
apolloconfig "github.com/apolloconfig/agollo/v4/env/config"
99
"github.com/apolloconfig/agollo/v4/extension"
1010

1111
"github.com/go-kratos/kratos/v2/config"
@@ -112,8 +112,8 @@ func NewSource(opts ...Option) config.Source {
112112
for _, o := range opts {
113113
o(&op)
114114
}
115-
client, err := agollo.StartWithConfig(func() (*apolloConfig.AppConfig, error) {
116-
return &apolloConfig.AppConfig{
115+
client, err := agollo.StartWithConfig(func() (*apolloconfig.AppConfig, error) {
116+
return &apolloconfig.AppConfig{
117117
AppID: op.appid,
118118
Cluster: op.cluster,
119119
NamespaceName: op.namespace,
@@ -166,14 +166,13 @@ func (e *apollo) load() []*config.KeyValue {
166166
}
167167
kvs = append(kvs, kv)
168168
continue
169-
} else {
170-
kv, err := e.getConfig(ns)
171-
if err != nil {
172-
log.Errorf("apollo get config failed,err:%v", err)
173-
continue
174-
}
175-
kvs = append(kvs, kv)
176169
}
170+
kv, err := e.getConfig(ns)
171+
if err != nil {
172+
log.Errorf("apollo get config failed,err:%v", err)
173+
continue
174+
}
175+
kvs = append(kvs, kv)
177176
}
178177
return kvs
179178
}

contrib/config/apollo/watcher.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (c *customChangeListener) OnChange(changeEvent *storage.ChangeEvent) {
7272
c.in <- change
7373
}
7474

75-
func (c *customChangeListener) OnNewestChange(changeEvent *storage.FullChangeEvent) {}
75+
func (c *customChangeListener) OnNewestChange(_ *storage.FullChangeEvent) {}
7676

7777
func newWatcher(a *apollo) (config.Watcher, error) {
7878
changeCh := make(chan []*config.KeyValue)

contrib/config/consul/watcher.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type watcher struct {
1818
cancel context.CancelFunc
1919
}
2020

21-
func (w *watcher) handle(idx uint64, data interface{}) {
21+
func (w *watcher) handle(_ uint64, data interface{}) {
2222
if data == nil {
2323
return
2424
}

contrib/log/aliyun/aliyun_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestWithAccessSecret(t *testing.T) {
5858
}
5959
}
6060

61-
func TestLogger(t *testing.T) {
61+
func TestLogger(_ *testing.T) {
6262
project := "foo"
6363
logger := NewAliyunLog(WithProject(project))
6464
defer logger.Close()

contrib/metrics/datadog/gauge.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ func (d *gauge) Set(value float64) {
3939
_ = d.opts.client.Gauge(d.name, value, d.lvs, d.opts.sampleRate)
4040
}
4141

42-
func (d *gauge) Add(delta float64) {
42+
func (d *gauge) Add(_ float64) {
4343
}
4444

45-
func (d *gauge) Sub(delta float64) {
45+
func (d *gauge) Sub(_ float64) {
4646
}

contrib/opensergo/opensergo_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type testMetadataServiceServer struct {
2323
srvContractPb.UnimplementedMetadataServiceServer
2424
}
2525

26-
func (m *testMetadataServiceServer) ReportMetadata(ctx context.Context, req *srvContractPb.ReportMetadataRequest) (*srvContractPb.ReportMetadataReply, error) {
26+
func (m *testMetadataServiceServer) ReportMetadata(_ context.Context, _ *srvContractPb.ReportMetadataRequest) (*srvContractPb.ReportMetadataReply, error) {
2727
return &srvContractPb.ReportMetadataReply{}, nil
2828
}
2929

contrib/registry/discovery/discovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func (r *Resolve) Watch() <-chan struct{} {
427427
}
428428

429429
// fetch resolver instance.
430-
func (r *Resolve) fetch(ctx context.Context) (ins *disInstancesInfo, ok bool) {
430+
func (r *Resolve) fetch(_ context.Context) (ins *disInstancesInfo, ok bool) {
431431
r.d.mutex.RLock()
432432
app, ok := r.d.apps[r.id]
433433
r.d.mutex.RUnlock()

contrib/registry/discovery/impl_registrar.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (d *Discovery) register(ctx context.Context, ins *discoveryInstance) (err e
122122
return
123123
}
124124

125-
func (d *Discovery) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
125+
func (d *Discovery) Deregister(_ context.Context, service *registry.ServiceInstance) error {
126126
ins := fromServerInstance(service, d.config)
127127
return d.cancel(ins)
128128
}

contrib/registry/eureka/register_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/go-kratos/kratos/v2/registry"
1212
)
1313

14-
func TestRegistry(t *testing.T) {
14+
func TestRegistry(_ *testing.T) {
1515
ctx := context.Background()
1616
ctx, cancel := context.WithCancel(ctx)
1717
s1 := &registry.ServiceInstance{
@@ -92,7 +92,7 @@ func do(r *Registry, s *registry.ServiceInstance) {
9292
}
9393
}
9494

95-
func TestLock(t *testing.T) {
95+
func TestLock(_ *testing.T) {
9696
type me struct {
9797
lock sync.Mutex
9898
}

contrib/registry/kubernetes/registry.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,14 @@ func (s *Registry) Register(ctx context.Context, service *registry.ServiceInstan
151151
}
152152

153153
// Deregister the registration.
154-
func (s *Registry) Deregister(ctx context.Context, service *registry.ServiceInstance) error {
154+
func (s *Registry) Deregister(ctx context.Context, _ *registry.ServiceInstance) error {
155155
return s.Register(ctx, &registry.ServiceInstance{
156156
Metadata: map[string]string{},
157157
})
158158
}
159159

160160
// GetService return the service instances in memory according to the service name.
161-
func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error) {
161+
func (s *Registry) GetService(_ context.Context, name string) ([]*registry.ServiceInstance, error) {
162162
pods, err := s.podLister.List(labels.SelectorFromSet(map[string]string{
163163
LabelsKeyServiceName: name,
164164
}))

contrib/registry/servicecomb/registry_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ func init() {
1919

2020
type mockClient struct{}
2121

22-
func (receiver *mockClient) WatchMicroService(microServiceID string, callback func(*sc.MicroServiceInstanceChangedEvent)) error {
22+
func (receiver *mockClient) WatchMicroService(_ string, _ func(*sc.MicroServiceInstanceChangedEvent)) error {
2323
return nil
2424
}
2525

2626
//nolint
27-
func (receiver *mockClient) FindMicroServiceInstances(consumerID,
28-
appID, microServiceName, versionRule string, opts ...sc.CallOption,
27+
func (receiver *mockClient) FindMicroServiceInstances(_,
28+
_, microServiceName, _ string, _ ...sc.CallOption,
2929
) ([]*pb.MicroServiceInstance, error) {
3030
if microServiceName == "KratosServicecomb" {
3131
return []*pb.MicroServiceInstance{{}}, nil
3232
}
3333
return nil, nil
3434
}
3535

36-
func (receiver *mockClient) RegisterService(microService *pb.MicroService) (string, error) {
36+
func (receiver *mockClient) RegisterService(_ *pb.MicroService) (string, error) {
3737
return "", nil
3838
}
3939

40-
func (receiver *mockClient) RegisterMicroServiceInstance(microServiceInstance *pb.MicroServiceInstance) (string, error) {
40+
func (receiver *mockClient) RegisterMicroServiceInstance(_ *pb.MicroServiceInstance) (string, error) {
4141
return "", nil
4242
}
4343

44-
func (receiver *mockClient) Heartbeat(microServiceID, microServiceInstanceID string) (bool, error) {
44+
func (receiver *mockClient) Heartbeat(_, _ string) (bool, error) {
4545
return true, nil
4646
}
4747

48-
func (receiver *mockClient) UnregisterMicroServiceInstance(microServiceID, microServiceInstanceID string) (bool, error) {
48+
func (receiver *mockClient) UnregisterMicroServiceInstance(_, _ string) (bool, error) {
4949
return true, nil
5050
}
5151

52-
func (receiver *mockClient) GetMicroServiceID(appID, microServiceName, version, env string, opts ...sc.CallOption) (string, error) {
52+
func (receiver *mockClient) GetMicroServiceID(_, _, _, _ string, _ ...sc.CallOption) (string, error) {
5353
return "", nil
5454
}
5555

contrib/registry/zookeeper/register.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func New(conn *zk.Conn, opts ...Option) *Registry {
5959
}
6060
}
6161

62-
func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error {
62+
func (r *Registry) Register(_ context.Context, service *registry.ServiceInstance) error {
6363
var (
6464
data []byte
6565
err error
@@ -100,7 +100,7 @@ func (r *Registry) Deregister(ctx context.Context, service *registry.ServiceInst
100100
}
101101

102102
// GetService get services from zookeeper
103-
func (r *Registry) GetService(ctx context.Context, serviceName string) ([]*registry.ServiceInstance, error) {
103+
func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error) {
104104
instances, err, _ := r.group.Do(serviceName, func() (interface{}, error) {
105105
serviceNamePath := path.Join(r.opts.namespace, serviceName)
106106
servicesID, _, err := r.conn.Children(serviceNamePath)

encoding/encoding_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99

1010
type codec struct{}
1111

12-
func (c codec) Marshal(v interface{}) ([]byte, error) {
12+
func (c codec) Marshal(_ interface{}) ([]byte, error) {
1313
panic("implement me")
1414
}
1515

16-
func (c codec) Unmarshal(data []byte, v interface{}) error {
16+
func (c codec) Unmarshal(_ []byte, _ interface{}) error {
1717
panic("implement me")
1818
}
1919

log/filter_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"testing"
77
)
88

9-
func TestFilterAll(t *testing.T) {
9+
func TestFilterAll(_ *testing.T) {
1010
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
1111
log := NewHelper(NewFilter(logger,
1212
FilterLevel(LevelDebug),
@@ -21,7 +21,7 @@ func TestFilterAll(t *testing.T) {
2121
log.Warn("warn log")
2222
}
2323

24-
func TestFilterLevel(t *testing.T) {
24+
func TestFilterLevel(_ *testing.T) {
2525
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
2626
log := NewHelper(NewFilter(NewFilter(logger, FilterLevel(LevelWarn))))
2727
log.Log(LevelDebug, "msg1", "te1st debug")
@@ -31,27 +31,27 @@ func TestFilterLevel(t *testing.T) {
3131
log.Warn("warn log")
3232
}
3333

34-
func TestFilterCaller(t *testing.T) {
34+
func TestFilterCaller(_ *testing.T) {
3535
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
3636
log := NewFilter(logger)
3737
_ = log.Log(LevelDebug, "msg1", "te1st debug")
3838
logHelper := NewHelper(NewFilter(logger))
3939
logHelper.Log(LevelDebug, "msg1", "te1st debug")
4040
}
4141

42-
func TestFilterKey(t *testing.T) {
42+
func TestFilterKey(_ *testing.T) {
4343
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
4444
log := NewHelper(NewFilter(logger, FilterKey("password")))
4545
log.Debugw("password", "123456")
4646
}
4747

48-
func TestFilterValue(t *testing.T) {
48+
func TestFilterValue(_ *testing.T) {
4949
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
5050
log := NewHelper(NewFilter(logger, FilterValue("debug")))
5151
log.Debugf("test %s", "debug")
5252
}
5353

54-
func TestFilterFunc(t *testing.T) {
54+
func TestFilterFunc(_ *testing.T) {
5555
logger := With(DefaultLogger, "ts", DefaultTimestamp, "caller", DefaultCaller)
5656
log := NewHelper(NewFilter(logger, FilterFunc(testFilterFunc)))
5757
log.Debug("debug level")

0 commit comments

Comments
 (0)