From 11add38e87291cd34cc14e6748fa7900ca2deff6 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Mon, 11 Dec 2023 13:18:34 +0300 Subject: [PATCH] [#857] golangci: Add protogetter linter Signed-off-by: Dmitrii Stepanov --- .golangci.yml | 1 + cmd/frostfs-cli/modules/control/evacuation.go | 6 +++--- cmd/frostfs-cli/modules/control/remove_rule.go | 2 +- cmd/frostfs-cli/modules/control/shards_list.go | 6 +++--- cmd/frostfs-cli/modules/tree/add.go | 2 +- pkg/services/control/ir/server/calls.go | 6 +++--- pkg/services/control/server/doctor.go | 4 ++-- pkg/services/control/server/set_shard_mode.go | 4 ++-- pkg/services/tree/service.go | 10 ++++++---- pkg/services/tree/sync.go | 6 +++--- 10 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4dd82d92..d209693a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -81,5 +81,6 @@ linters: - truecloudlab-linters - perfsprint - testifylint + - protogetter disable-all: true fast: false diff --git a/cmd/frostfs-cli/modules/control/evacuation.go b/cmd/frostfs-cli/modules/control/evacuation.go index 735897b8..821dd1a6 100644 --- a/cmd/frostfs-cli/modules/control/evacuation.go +++ b/cmd/frostfs-cli/modules/control/evacuation.go @@ -220,7 +220,7 @@ func appendEstimation(sb *strings.Builder, resp *control.GetShardEvacuationStatu if resp.GetBody().GetStatus() != control.GetShardEvacuationStatusResponse_Body_RUNNING || resp.GetBody().GetDuration() == nil || resp.GetBody().GetTotal() == 0 || - resp.GetBody().GetEvacuated()+resp.GetBody().GetFailed()+resp.Body.GetSkipped() == 0 { + resp.GetBody().GetEvacuated()+resp.GetBody().GetFailed()+resp.GetBody().GetSkipped() == 0 { return } @@ -252,8 +252,8 @@ func appendStartedAt(sb *strings.Builder, resp *control.GetShardEvacuationStatus } func appendError(sb *strings.Builder, resp *control.GetShardEvacuationStatusResponse) { - if len(resp.Body.GetErrorMessage()) > 0 { - sb.WriteString(fmt.Sprintf(" Error: %s.", resp.Body.GetErrorMessage())) + if len(resp.GetBody().GetErrorMessage()) > 0 { + sb.WriteString(fmt.Sprintf(" Error: %s.", resp.GetBody().GetErrorMessage())) } } diff --git a/cmd/frostfs-cli/modules/control/remove_rule.go b/cmd/frostfs-cli/modules/control/remove_rule.go index c3f4aeb0..60f96afd 100644 --- a/cmd/frostfs-cli/modules/control/remove_rule.go +++ b/cmd/frostfs-cli/modules/control/remove_rule.go @@ -63,7 +63,7 @@ func removeRule(cmd *cobra.Command, _ []string) { verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) - if resp.GetBody().Removed { + if resp.GetBody().GetRemoved() { cmd.Println("Rule has been removed.") } else { cmd.Println("Rule has not been removed.") diff --git a/cmd/frostfs-cli/modules/control/shards_list.go b/cmd/frostfs-cli/modules/control/shards_list.go index 4d09667b..0b5d6b0a 100644 --- a/cmd/frostfs-cli/modules/control/shards_list.go +++ b/cmd/frostfs-cli/modules/control/shards_list.go @@ -65,7 +65,7 @@ func prettyPrintShardsJSON(cmd *cobra.Command, ii []*control.ShardInfo) { out := make([]map[string]any, 0, len(ii)) for _, i := range ii { out = append(out, map[string]any{ - "shard_id": base58.Encode(i.Shard_ID), + "shard_id": base58.Encode(i.GetShard_ID()), "mode": shardModeToString(i.GetMode()), "metabase": i.GetMetabasePath(), "blobstor": i.GetBlobstor(), @@ -105,7 +105,7 @@ func prettyPrintShards(cmd *cobra.Command, ii []*control.ShardInfo) { pathPrinter("Write-cache", i.GetWritecachePath())+ pathPrinter("Pilorama", i.GetPiloramaPath())+ fmt.Sprintf("Error count: %d\n", i.GetErrorCount()), - base58.Encode(i.Shard_ID), + base58.Encode(i.GetShard_ID()), shardModeToString(i.GetMode()), ) } @@ -122,6 +122,6 @@ func shardModeToString(m control.ShardMode) string { func sortShardsByID(ii []*control.ShardInfo) { sort.Slice(ii, func(i, j int) bool { - return bytes.Compare(ii[i].Shard_ID, ii[j].Shard_ID) < 0 + return bytes.Compare(ii[i].GetShard_ID(), ii[j].GetShard_ID()) < 0 }) } diff --git a/cmd/frostfs-cli/modules/tree/add.go b/cmd/frostfs-cli/modules/tree/add.go index 4ac1ed19..8ceea417 100644 --- a/cmd/frostfs-cli/modules/tree/add.go +++ b/cmd/frostfs-cli/modules/tree/add.go @@ -74,7 +74,7 @@ func add(cmd *cobra.Command, _ []string) { resp, err := cli.Add(ctx, req) commonCmd.ExitOnErr(cmd, "failed to cal add: %w", err) - cmd.Println("Node ID: ", resp.Body.NodeId) + cmd.Println("Node ID: ", resp.GetBody().GetNodeId()) } func parseMeta(cmd *cobra.Command) ([]*tree.KeyValue, error) { diff --git a/pkg/services/control/ir/server/calls.go b/pkg/services/control/ir/server/calls.go index 7baae032..58610b0d 100644 --- a/pkg/services/control/ir/server/calls.go +++ b/pkg/services/control/ir/server/calls.go @@ -114,13 +114,13 @@ func (s *Server) RemoveContainer(_ context.Context, req *control.RemoveContainer return nil, status.Error(codes.PermissionDenied, err.Error()) } - if len(req.Body.GetContainerId()) > 0 && len(req.Body.GetOwner()) > 0 { + if len(req.GetBody().GetContainerId()) > 0 && len(req.GetBody().GetOwner()) > 0 { return nil, status.Error(codes.InvalidArgument, "specify the owner and container at the same time is not allowed") } var vub uint32 - if len(req.Body.GetContainerId()) > 0 { + if len(req.GetBody().GetContainerId()) > 0 { var containerID cid.ID - if err := containerID.Decode(req.Body.GetContainerId()); err != nil { + if err := containerID.Decode(req.GetBody().GetContainerId()); err != nil { return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("failed to parse container ID: %s", err.Error())) } var err error diff --git a/pkg/services/control/server/doctor.go b/pkg/services/control/server/doctor.go index 2c91d4c2..707a6c98 100644 --- a/pkg/services/control/server/doctor.go +++ b/pkg/services/control/server/doctor.go @@ -15,12 +15,12 @@ func (s *Server) Doctor(ctx context.Context, req *control.DoctorRequest) (*contr return nil, status.Error(codes.PermissionDenied, err.Error()) } - if !req.Body.RemoveDuplicates { + if !req.GetBody().GetRemoveDuplicates() { return nil, status.Error(codes.InvalidArgument, "operation not specified") } var prm engine.RemoveDuplicatesPrm - prm.Concurrency = int(req.Body.Concurrency) + prm.Concurrency = int(req.GetBody().GetConcurrency()) err = s.s.RemoveDuplicates(ctx, prm) if err != nil { diff --git a/pkg/services/control/server/set_shard_mode.go b/pkg/services/control/server/set_shard_mode.go index 274e2f65..18a7eb32 100644 --- a/pkg/services/control/server/set_shard_mode.go +++ b/pkg/services/control/server/set_shard_mode.go @@ -36,8 +36,8 @@ func (s *Server) SetShardMode(_ context.Context, req *control.SetShardModeReques return nil, status.Error(codes.Internal, fmt.Sprintf("unknown shard mode: %s", requestedMode)) } - for _, shardID := range s.getShardIDList(req.Body.GetShard_ID()) { - err = s.s.SetShardMode(shardID, m, req.Body.GetResetErrorCounter()) + for _, shardID := range s.getShardIDList(req.GetBody().GetShard_ID()) { + err = s.s.SetShardMode(shardID, m, req.GetBody().GetResetErrorCounter()) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/pkg/services/tree/service.go b/pkg/services/tree/service.go index 57767f87..59b01796 100644 --- a/pkg/services/tree/service.go +++ b/pkg/services/tree/service.go @@ -369,13 +369,14 @@ func (s *Service) GetNodeByPath(ctx context.Context, req *GetNodeByPathRequest) x.ParentId = parent x.NodeId = node x.Timestamp = m.Time - if b.AllAttributes { + if b.GetAllAttributes() { x.Meta = metaToProto(m.Items) } else { + var metaValue []*KeyValue for _, kv := range m.Items { for _, attr := range b.GetAttributes() { if kv.Key == attr { - x.Meta = append(x.Meta, &KeyValue{ + metaValue = append(metaValue, &KeyValue{ Key: kv.Key, Value: kv.Value, }) @@ -383,6 +384,7 @@ func (s *Service) GetNodeByPath(ctx context.Context, req *GetNodeByPathRequest) } } } + x.Meta = metaValue } info = append(info, &x) } @@ -670,8 +672,8 @@ func protoToMeta(arr []*KeyValue) []pilorama.KeyValue { meta := make([]pilorama.KeyValue, len(arr)) for i, kv := range arr { if kv != nil { - meta[i].Key = kv.Key - meta[i].Value = kv.Value + meta[i].Key = kv.GetKey() + meta[i].Value = kv.GetValue() } } return meta diff --git a/pkg/services/tree/sync.go b/pkg/services/tree/sync.go index 485278ad..2a19ae18 100644 --- a/pkg/services/tree/sync.go +++ b/pkg/services/tree/sync.go @@ -243,10 +243,10 @@ func (s *Service) startStream(ctx context.Context, cid cid.ID, treeID string, for ; err == nil; res, err = c.Recv() { lm := res.GetBody().GetOperation() m := &pilorama.Move{ - Parent: lm.ParentId, - Child: lm.ChildId, + Parent: lm.GetParentId(), + Child: lm.GetChildId(), } - if err := m.Meta.FromBytes(lm.Meta); err != nil { + if err := m.Meta.FromBytes(lm.GetMeta()); err != nil { return err } opsCh <- m