Skip to content

Commit

Permalink
fix: rectification of non-standard lint codes (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito authored Mar 21, 2023
1 parent 0c2d263 commit 9a973d2
Show file tree
Hide file tree
Showing 57 changed files with 116 additions and 119 deletions.
4 changes: 2 additions & 2 deletions api/metadata/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/change/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/proto/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/kratos/internal/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-go-http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
}

Expand Down
19 changes: 9 additions & 10 deletions contrib/config/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/config/apollo/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion contrib/config/consul/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/log/aliyun/aliyun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions contrib/metrics/datadog/gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
2 changes: 1 addition & 1 deletion contrib/opensergo/opensergo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion contrib/registry/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion contrib/registry/discovery/impl_registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions contrib/registry/eureka/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/registry/kubernetes/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}))
Expand Down
16 changes: 8 additions & 8 deletions contrib/registry/servicecomb/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,37 @@ 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
}
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
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/registry/zookeeper/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions encoding/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
12 changes: 6 additions & 6 deletions log/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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")
Expand All @@ -31,27 +31,27 @@ 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")
logHelper := NewHelper(NewFilter(logger))
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")
Expand Down
Loading

0 comments on commit 9a973d2

Please sign in to comment.