diff --git a/Makefile b/Makefile index 0848657574..af71e75e33 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \ sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \ sed "s/-/~/")-${OS_RELEASE} -.PHONY: help all images dep clean fmts fmt imports test lint docker/lint +.PHONY: help all images dep clean fmts fmt modernize imports test lint docker/lint prepare-release debpackage # To build a specific binary, use it's name prefix with bin/ as a target @@ -111,7 +111,7 @@ docker/%: # Run all code formatters -fmts: fmt imports +fmts: fmt imports modernize # Reformat code fmt: @@ -123,6 +123,11 @@ imports: @echo "⇒ Processing goimports check" @goimports -w $$(find . -type f -name '*.go' -not -path '*.pb.go') +# Prettify code +modernize: + @echo "⇒ Processing modernize check" + @go run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix ./... + # Run Unit Test with go test test: @echo "⇒ Running go test" diff --git a/cmd/neofs-adm/internal/modules/fschain/deploy.go b/cmd/neofs-adm/internal/modules/fschain/deploy.go index 949412e1bb..a0b2c93b79 100644 --- a/cmd/neofs-adm/internal/modules/fschain/deploy.go +++ b/cmd/neofs-adm/internal/modules/fschain/deploy.go @@ -209,8 +209,8 @@ func probeContractName(ctrPath string) (string, error) { var ctrName string for i := range ds { - if strings.HasSuffix(ds[i].Name(), "_contract.nef") { - ctrName = strings.TrimSuffix(ds[i].Name(), "_contract.nef") + if before, ok := strings.CutSuffix(ds[i].Name(), "_contract.nef"); ok { + ctrName = before break } } diff --git a/cmd/neofs-adm/internal/modules/storagecfg/root.go b/cmd/neofs-adm/internal/modules/storagecfg/root.go index 93e6002f1a..923af2bf10 100644 --- a/cmd/neofs-adm/internal/modules/storagecfg/root.go +++ b/cmd/neofs-adm/internal/modules/storagecfg/root.go @@ -305,8 +305,8 @@ func (filenameCompleter) Do(line []rune, pos int) (newLine [][]rune, length int) for i := range de { name := filepath.Join(dir, de[i].Name()) - if strings.HasPrefix(name, prefix) { - tail := []rune(strings.TrimPrefix(name, prefix)) + if after, ok := strings.CutPrefix(name, prefix); ok { + tail := []rune(after) if de[i].IsDir() { tail = append(tail, filepath.Separator) } diff --git a/cmd/neofs-node/policy_test.go b/cmd/neofs-node/policy_test.go index 6d5bf4e8b4..51a466fc20 100644 --- a/cmd/neofs-node/policy_test.go +++ b/cmd/neofs-node/policy_test.go @@ -95,11 +95,8 @@ func newNetmapWithContainer(tb testing.TB, nodeNum int, selected ...[]int) ([]ne nodes[i].SetPublicKey(key) for j := range selected { - for k := range selected[j] { - if i == selected[j][k] { - nodes[i].SetAttribute("attr"+strconv.Itoa(j), "true") - break - } + if slices.Contains(selected[j], i) { + nodes[i].SetAttribute("attr"+strconv.Itoa(j), "true") } } } diff --git a/pkg/innerring/internal/blockchain/blockchain.go b/pkg/innerring/internal/blockchain/blockchain.go index 140e4f258a..24676e11a8 100644 --- a/pkg/innerring/internal/blockchain/blockchain.go +++ b/pkg/innerring/internal/blockchain/blockchain.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "maps" "math" "time" @@ -169,10 +170,7 @@ func New(cfg *config.Consensus, wallet *config.Wallet, errChan chan<- error, log cfgBaseProto.Genesis.MaxValidUntilBlockIncrement = cfg.MaxValidUntilBlockIncrement cfgBaseProto.Hardforks = cfg.Hardforks.Name if cfg.ValidatorsHistory.Height != nil { - cfgBaseProto.ValidatorsHistory = make(map[uint32]uint32, len(cfg.ValidatorsHistory.Height)) - for height, num := range cfg.ValidatorsHistory.Height { - cfgBaseProto.ValidatorsHistory[height] = num - } + cfgBaseProto.ValidatorsHistory = maps.Clone(cfg.ValidatorsHistory.Height) } else { cfgBaseProto.ValidatorsCount = uint32(len(standByCommittee)) } diff --git a/pkg/local_object_storage/metabase/put_test.go b/pkg/local_object_storage/metabase/put_test.go index 5db80d2095..1ec1969644 100644 --- a/pkg/local_object_storage/metabase/put_test.go +++ b/pkg/local_object_storage/metabase/put_test.go @@ -677,10 +677,7 @@ func BenchmarkPutBatch(b *testing.B) { b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i += 10 { - end := i + 10 - if end > b.N { - end = b.N - } + end := min(i+10, b.N) if err := db.PutBatch(objs[i:end]); err != nil { b.Fatal(err) } @@ -693,10 +690,7 @@ func BenchmarkPutBatch(b *testing.B) { b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i += 100 { - end := i + 100 - if end > b.N { - end = b.N - } + end := min(i+100, b.N) if err := db.PutBatch(objs[i:end]); err != nil { b.Fatal(err) } @@ -709,10 +703,7 @@ func BenchmarkPutBatch(b *testing.B) { b.ResetTimer() b.ReportAllocs() for i := 0; i < b.N; i += 1000 { - end := i + 1000 - if end > b.N { - end = b.N - } + end := min(i+1000, b.N) if err := db.PutBatch(objs[i:end]); err != nil { b.Fatal(err) } diff --git a/pkg/morph/client/netmap/add_peer.go b/pkg/morph/client/netmap/add_peer.go index 5911b4502c..7a09afad1d 100644 --- a/pkg/morph/client/netmap/add_peer.go +++ b/pkg/morph/client/netmap/add_peer.go @@ -2,6 +2,7 @@ package netmap import ( "fmt" + "maps" "slices" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" @@ -19,9 +20,7 @@ func (c *Client) AddPeer(ni netmap.NodeInfo, pkey *keys.PublicKey) error { State: netmaprpc.NodeStateOnline, } node.Addresses = slices.Collect(ni.NetworkEndpoints()) - for k, v := range ni.Attributes() { - node.Attributes[k] = v - } + maps.Insert(node.Attributes, ni.Attributes()) prm := client.InvokePrm{} prm.SetMethod(addNodeMethod) diff --git a/pkg/services/meta/notifications.go b/pkg/services/meta/notifications.go index f09d08d9d8..3437fff810 100644 --- a/pkg/services/meta/notifications.go +++ b/pkg/services/meta/notifications.go @@ -624,14 +624,12 @@ func (m *Meta) handleEpochNotification(e uint64) error { defer m.stM.RUnlock() var gcWG sync.WaitGroup for cID, st := range m.storages { - gcWG.Add(1) - go func() { - defer gcWG.Done() + gcWG.Go(func() { err := st.handleNewEpoch(e) if err != nil { l.Error("handling new epoch", zap.Stringer("cID", cID), zap.Error(err)) } - }() + }) } gcWG.Wait() diff --git a/pkg/services/object/get/assemble.go b/pkg/services/object/get/assemble.go index 33538b75d4..4a05aef3d8 100644 --- a/pkg/services/object/get/assemble.go +++ b/pkg/services/object/get/assemble.go @@ -128,10 +128,7 @@ func (exec *execCtx) initFromChild(obj oid.ID) (*oid.ID, []oid.ID) { to := uint64(0) if seekOff+seekLen > startRight+from { - to = seekOff + seekLen - startRight - if to > childSize { - to = childSize - } + to = min(seekOff+seekLen-startRight, childSize) } segLen := uint64(0) diff --git a/pkg/services/object/put/distibuted_test.go b/pkg/services/object/put/distibuted_test.go index abdfd01c8e..300b69f7c6 100644 --- a/pkg/services/object/put/distibuted_test.go +++ b/pkg/services/object/put/distibuted_test.go @@ -22,7 +22,7 @@ func allocNodes(n []uint) [][]netmap.NodeInfo { for i := range res { res[i] = make([]netmap.NodeInfo, n[i]) for j := range res[i] { - res[i][j].SetPublicKey([]byte(fmt.Sprintf("pub_%d_%d", i, j))) + res[i][j].SetPublicKey(fmt.Appendf(nil, "pub_%d_%d", i, j)) res[i][j].SetNetworkEndpoints( "localhost:"+strconv.Itoa(1e4+i*100+2*j), "localhost:"+strconv.Itoa(1e4+i*100+2*j+1),