diff --git a/container/container.go b/container/container.go index 8c9c447..e2e796b 100644 --- a/container/container.go +++ b/container/container.go @@ -308,7 +308,7 @@ func (x *Container) SetAttribute(key, value string) { attrs := x.v2.GetAttributes() ln := len(attrs) - for i := 0; i < ln; i++ { + for i := range ln { if attrs[i].GetKey() == key { attrs[i].SetValue(value) return diff --git a/eacl/record.go b/eacl/record.go index eeb9646..3c0d44a 100644 --- a/eacl/record.go +++ b/eacl/record.go @@ -286,13 +286,13 @@ func equalRecords(r1, r2 Record) bool { return false } - for i := 0; i < len(fs1); i++ { + for i := range len(fs1) { if !equalFilters(fs1[i], fs2[i]) { return false } } - for i := 0; i < len(ts1); i++ { + for i := range len(ts1) { if !equalTargets(ts1[i], ts2[i]) { return false } diff --git a/eacl/table.go b/eacl/table.go index b16467b..6982b85 100644 --- a/eacl/table.go +++ b/eacl/table.go @@ -212,7 +212,7 @@ func EqualTables(t1, t2 Table) bool { return false } - for i := 0; i < len(rs1); i++ { + for i := range len(rs1) { if !equalRecords(rs1[i], rs2[i]) { return false } diff --git a/eacl/target.go b/eacl/target.go index 5e34950..2b8b709 100644 --- a/eacl/target.go +++ b/eacl/target.go @@ -51,7 +51,7 @@ func SetTargetECDSAKeys(t *Target, pubs ...*ecdsa.PublicKey) { binKeys = make([][]byte, 0, ln) } - for i := 0; i < ln; i++ { + for i := range ln { binKeys = append(binKeys, (*keys.PublicKey)(pubs[i]).Bytes()) } @@ -67,7 +67,7 @@ func TargetECDSAKeys(t *Target) []*ecdsa.PublicKey { pubs := make([]*ecdsa.PublicKey, ln) - for i := 0; i < ln; i++ { + for i := range ln { p := new(keys.PublicKey) if p.DecodeBytes(binKeys[i]) == nil { pubs[i] = (*ecdsa.PublicKey)(p) @@ -169,7 +169,7 @@ func equalTargets(t1, t2 Target) bool { return false } - for i := 0; i < len(keys1); i++ { + for i := range len(keys1) { if !bytes.Equal(keys1[i], keys2[i]) { return false } diff --git a/eacl/test/benchmark_test.go b/eacl/test/benchmark_test.go index 865789b..e4f91c0 100644 --- a/eacl/test/benchmark_test.go +++ b/eacl/test/benchmark_test.go @@ -19,7 +19,7 @@ func baseBenchmarkTableBinaryComparison(b *testing.B, factor int) { b.StopTimer() b.ResetTimer() b.StartTimer() - for i := 0; i < b.N; i++ { + for range b.N { got, _ := t.Marshal() if !bytes.Equal(exp, got) { b.Fail() @@ -38,7 +38,7 @@ func baseBenchmarkTableEqualsComparison(b *testing.B, factor int) { b.StopTimer() b.ResetTimer() b.StartTimer() - for i := 0; i < b.N; i++ { + for range b.N { if !eacl.EqualTables(*t, *t2) { b.Fail() } @@ -76,7 +76,7 @@ func TargetN(n int) *eacl.Target { x.SetRole(eacl.RoleSystem) keys := make([][]byte, n) - for i := 0; i < n; i++ { + for i := range n { keys[i] = make([]byte, 32) rand.Read(keys[i]) } @@ -94,7 +94,7 @@ func RecordN(n int) *eacl.Record { x.SetOperation(eacl.OperationRangeHash) x.SetTargets(*TargetN(n)) - for i := 0; i < n; i++ { + for range n { x.AddFilter(eacl.HeaderFromObject, eacl.MatchStringEqual, "", cidtest.ID().EncodeToString()) } @@ -106,7 +106,7 @@ func TableN(n int) *eacl.Table { x.SetCID(cidtest.ID()) - for i := 0; i < n; i++ { + for range n { x.AddRecord(RecordN(n)) } diff --git a/netmap/bench_test.go b/netmap/bench_test.go index e0dc7c5..cd3dfac 100644 --- a/netmap/bench_test.go +++ b/netmap/bench_test.go @@ -47,7 +47,7 @@ func BenchmarkNetmap_ContainerNodes(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { _, err := nm.ContainerNodes(p, pivot) if err != nil { b.Fatal(err) diff --git a/netmap/selector_test.go b/netmap/selector_test.go index 797ccfc..2d54987 100644 --- a/netmap/selector_test.go +++ b/netmap/selector_test.go @@ -38,7 +38,7 @@ func BenchmarkHRWSort(b *testing.B) { b.Run("sort by index, no weight", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() copy(realNodes, vectors) b.StartTimer() @@ -49,7 +49,7 @@ func BenchmarkHRWSort(b *testing.B) { b.Run("sort by value, no weight", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() copy(realNodes, vectors) b.StartTimer() @@ -60,7 +60,7 @@ func BenchmarkHRWSort(b *testing.B) { b.Run("only sort by index", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() copy(realNodes, vectors) b.StartTimer() @@ -71,7 +71,7 @@ func BenchmarkHRWSort(b *testing.B) { b.Run("sort by value", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() copy(realNodes, vectors) b.StartTimer() @@ -82,7 +82,7 @@ func BenchmarkHRWSort(b *testing.B) { b.Run("sort by ID, then by index (deterministic)", func(b *testing.B) { realNodes := make([]nodes, netmapSize) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StopTimer() copy(realNodes, vectors) b.StartTimer() @@ -134,7 +134,7 @@ func BenchmarkPolicyHRWType(b *testing.B) { nm.SetNodes(nodes) b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { _, err := nm.ContainerNodes(p, []byte{1}) if err != nil { b.Fatal() @@ -195,7 +195,7 @@ func TestPlacementPolicy_DeterministicOrder(t *testing.T) { } a, b := getIndices(t) - for i := 0; i < 10; i++ { + for range 10 { x, y := getIndices(t) require.Equal(t, a, x) require.Equal(t, b, y) @@ -352,7 +352,7 @@ func TestPlacementPolicy_Unique(t *testing.T) { var nodes []NodeInfo for i, city := range []string{"Moscow", "Berlin", "Shenzhen"} { - for j := 0; j < 3; j++ { + for j := range 3 { node := nodeInfoFromAttributes("City", city) node.SetPublicKey(binary.BigEndian.AppendUint16(nil, uint16(i*4+j))) nodes = append(nodes, node) @@ -366,7 +366,7 @@ func TestPlacementPolicy_Unique(t *testing.T) { require.NoError(t, err) for i, vi := range v { for _, ni := range vi { - for j := 0; j < i; j++ { + for j := range i { for _, nj := range v[j] { require.NotEqual(t, ni.hash, nj.hash) } @@ -455,7 +455,7 @@ func TestPlacementPolicy_MultiREP(t *testing.T) { for _, additional := range []int{0, 1, 2} { t.Run(fmt.Sprintf("unique=%t, additional=%d", unique, additional), func(t *testing.T) { rs := []ReplicaDescriptor{newReplica(1, "SameRU")} - for i := 0; i < additional; i++ { + for range additional { rs = append(rs, newReplica(1, "")) } diff --git a/netmap/yml_test.go b/netmap/yml_test.go index a744a01..4df6e0a 100644 --- a/netmap/yml_test.go +++ b/netmap/yml_test.go @@ -130,7 +130,7 @@ func BenchmarkPlacementPolicyInteropability(b *testing.B) { b.Run(name, func(b *testing.B) { b.ReportAllocs() b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { b.StartTimer() v, err := nm.ContainerNodes(tt.Policy, tt.Pivot) b.StopTimer() @@ -173,7 +173,7 @@ func BenchmarkManySelects(b *testing.B) { b.ResetTimer() b.ReportAllocs() - for i := 0; i < b.N; i++ { + for range b.N { _, err = nm.ContainerNodes(tt.Policy, tt.Pivot) if err != nil { b.FailNow() diff --git a/object/erasurecode/reconstruct_test.go b/object/erasurecode/reconstruct_test.go index b638a4f..8397f44 100644 --- a/object/erasurecode/reconstruct_test.go +++ b/object/erasurecode/reconstruct_test.go @@ -53,7 +53,7 @@ func TestErasureCodeReconstruct(t *testing.T) { }) t.Run("from parity", func(t *testing.T) { parts := cloneSlice(parts) - for i := 0; i < parityCount; i++ { + for i := range parityCount { parts[i] = nil } reconstructed, err := c.ReconstructHeader(parts) @@ -138,7 +138,7 @@ func TestErasureCodeReconstruct(t *testing.T) { }) t.Run("from parity", func(t *testing.T) { parts := cloneSlice(parts) - for i := 0; i < parityCount; i++ { + for i := range parityCount { parts[i] = nil } reconstructed, err := c.Reconstruct(parts) @@ -180,7 +180,7 @@ func TestErasureCodeReconstruct(t *testing.T) { t.Run("from parity", func(t *testing.T) { oldParts := parts parts := cloneSlice(parts) - for i := 0; i < parityCount; i++ { + for i := range parityCount { parts[i] = nil } diff --git a/object/id/id_test.go b/object/id/id_test.go index bdc0b4d..3f35a3b 100644 --- a/object/id/id_test.go +++ b/object/id/id_test.go @@ -61,7 +61,7 @@ func TestID_Equal(t *testing.T) { func TestID_Parse(t *testing.T) { t.Run("should parse successful", func(t *testing.T) { - for i := 0; i < 10; i++ { + for i := range 10 { t.Run(strconv.Itoa(i), func(t *testing.T) { cs := randSHA256Checksum(t) str := base58.Encode(cs[:]) @@ -78,7 +78,7 @@ func TestID_Parse(t *testing.T) { }) t.Run("should failure on parse", func(t *testing.T) { - for i := 0; i < 10; i++ { + for i := range 10 { j := i t.Run(strconv.Itoa(j), func(t *testing.T) { cs := []byte{1, 2, 3, 4, 5, byte(j)} @@ -98,7 +98,7 @@ func TestID_String(t *testing.T) { }) t.Run("should be equal", func(t *testing.T) { - for i := 0; i < 10; i++ { + for i := range 10 { t.Run(strconv.Itoa(i), func(t *testing.T) { cs := randSHA256Checksum(t) str := base58.Encode(cs[:]) diff --git a/object/tombstone_test.go b/object/tombstone_test.go index 9825133..e819b22 100644 --- a/object/tombstone_test.go +++ b/object/tombstone_test.go @@ -14,7 +14,7 @@ func generateIDList(sz int) []oid.ID { res := make([]oid.ID, sz) cs := [sha256.Size]byte{} - for i := 0; i < sz; i++ { + for i := range sz { var oID oid.ID res[i] = oID diff --git a/object/transformer/transformer_test.go b/object/transformer/transformer_test.go index 97b2b01..a170835 100644 --- a/object/transformer/transformer_test.go +++ b/object/transformer/transformer_test.go @@ -72,7 +72,7 @@ func TestTransformer(t *testing.T) { require.Equal(t, ids.ParentID, &parID) children := tt.objects[i].Children() - for j := 0; j < i; j++ { + for j := range i { id, ok := tt.objects[j].ID() require.True(t, ok) require.Equal(t, id, children[j]) @@ -152,7 +152,7 @@ func benchmarkTransformer(b *testing.B, header *objectSDK.Object, payloadSize, s b.ReportAllocs() b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { f, _ := newPayloadSizeLimiter(maxSize, uint64(sizeHint), func() ObjectWriter { return benchTarget{} }) if err := f.WriteHeader(ctx, header); err != nil { b.Fatalf("write header: %v", err) diff --git a/pool/pool.go b/pool/pool.go index 264c69a..36d6340 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -2256,7 +2256,7 @@ func (p *innerPool) connection() (client, error) { return nil, errors.New("no healthy client") } attempts := 3 * len(p.clients) - for k := 0; k < attempts; k++ { + for range attempts { i := p.sampler.Next() if cp := p.clients[i]; cp.isHealthy() { return cp, nil diff --git a/pool/pool_test.go b/pool/pool_test.go index 9189c3e..656524a 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -222,7 +222,7 @@ func TestOneOfTwoFailed(t *testing.T) { time.Sleep(2 * time.Second) - for i := 0; i < 5; i++ { + for range 5 { cp, err := pool.connection() require.NoError(t, err) st, _ := pool.cache.Get(formCacheKey(cp.address(), pool.key, false)) @@ -514,7 +514,7 @@ func TestStatusMonitor(t *testing.T) { monitor.errorThreshold = 3 count := 10 - for i := 0; i < count; i++ { + for range count { monitor.incErrorRate() } @@ -724,7 +724,7 @@ func TestSwitchAfterErrorThreshold(t *testing.T) { require.NoError(t, err) t.Cleanup(pool.Close) - for i := 0; i < errorThreshold; i++ { + for range errorThreshold { conn, err := pool.connection() require.NoError(t, err) require.Equal(t, nodes[0].address, conn.address()) diff --git a/pool/sampler.go b/pool/sampler.go index 6f46886..95d875b 100644 --- a/pool/sampler.go +++ b/pool/sampler.go @@ -30,7 +30,7 @@ func newSampler(probabilities []float64, source rand.Source) *sampler { sampler.alias = make([]int, n) // Compute scaled probabilities. p := make([]float64, n) - for i := 0; i < n; i++ { + for i := range n { p[i] = probabilities[i] * float64(n) } for i, pi := range p { diff --git a/pool/sampler_test.go b/pool/sampler_test.go index 5ece768..ab06e0f 100644 --- a/pool/sampler_test.go +++ b/pool/sampler_test.go @@ -32,7 +32,7 @@ func TestSamplerStability(t *testing.T) { for _, tc := range cases { sampler := newSampler(tc.probabilities, rand.NewSource(0)) res := make([]int, len(tc.probabilities)) - for i := 0; i < COUNT; i++ { + for range COUNT { res[sampler.Next()]++ } diff --git a/pool/tree/pool.go b/pool/tree/pool.go index 21f7c54..3b0ff1a 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -382,7 +382,7 @@ type SubTreeReader struct { // Read reads another list of the subtree nodes. func (x *SubTreeReader) Read(buf []*grpcService.GetSubTreeResponse_Body) (int, error) { - for i := 0; i < len(buf); i++ { + for i := range len(buf) { resp, err := x.cli.Recv() if err == io.EOF { return i, io.EOF