Skip to content

Commit daaf66f

Browse files
committed
refactor: run go fix ./...
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
1 parent f40f40e commit daaf66f

22 files changed

Lines changed: 59 additions & 76 deletions

File tree

cmd/protoc-gen-protodb/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *mod) InitContext(c pgs.BuildContext) {
5050
p.ModuleBase.InitContext(c)
5151
p.ctx = pgsgo.InitContext(c.Parameters())
5252

53-
tpl := template.New("protodb").Funcs(map[string]interface{}{
53+
tpl := template.New("protodb").Funcs(map[string]any{
5454
"package": p.ctx.PackageName,
5555
"name": p.ctx.Name,
5656
"enabled": func(m pgs.Message) bool {

cmp.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package protodb
1717
import (
1818
"bytes"
1919
"fmt"
20+
"maps"
2021

2122
"google.golang.org/protobuf/proto"
2223
"google.golang.org/protobuf/reflect/protoreflect"
@@ -125,9 +126,7 @@ func cmpField(f protoreflect.FieldDescriptor, v1, v2 protoreflect.Value, prefix
125126
if len(mdiff) == 0 {
126127
return
127128
}
128-
for k, v := range mdiff {
129-
diffs[k] = v
130-
}
129+
maps.Copy(diffs, mdiff)
131130
return
132131
}
133132
if !equals {
@@ -179,10 +178,7 @@ func cmp(m1, m2 proto.Message, prefix string) map[string]*pb.FieldDiff {
179178
}
180179
}
181180
if l2Length > l1Length {
182-
start := l1Length - 1
183-
if start < 0 {
184-
start = 0
185-
}
181+
start := max(l1Length-1, 0)
186182
for i := start; i < l2Length; i++ {
187183
p := fmt.Sprintf("%s%s[%d]", prefix, f.Name(), i)
188184
cmpField(f, protoreflect.Value{}, l2.Get(i), p, diffs)

internal/badgerd/logger.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ type logWrapper struct {
2727
badger.Logger
2828
}
2929

30-
func (l *logWrapper) Errorf(s string, i ...interface{}) {
30+
func (l *logWrapper) Errorf(s string, i ...any) {
3131
l.log(l.Logger.Errorf, s, i...)
3232
}
3333

34-
func (l *logWrapper) Warningf(s string, i ...interface{}) {
34+
func (l *logWrapper) Warningf(s string, i ...any) {
3535
l.log(l.Logger.Warningf, s, i...)
3636
}
3737

38-
func (l *logWrapper) Infof(s string, i ...interface{}) {
38+
func (l *logWrapper) Infof(s string, i ...any) {
3939
l.log(l.Logger.Infof, s, i...)
4040
}
4141

42-
func (l *logWrapper) Debugf(s string, i ...interface{}) {
42+
func (l *logWrapper) Debugf(s string, i ...any) {
4343
l.log(l.Logger.Debugf, s, i...)
4444
}
4545

46-
func (l *logWrapper) log(fn func(string, ...interface{}), s string, i ...interface{}) {
46+
func (l *logWrapper) log(fn func(string, ...any), s string, i ...any) {
4747
msg := fmt.Sprintf(s, i...)
48-
for _, v := range strings.Split(msg, "\n") {
48+
for v := range strings.SplitSeq(msg, "\n") {
4949
if v == "" {
5050
continue
5151
}

internal/badgerd/options.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ var (
2727
)
2828

2929
type Logger interface {
30-
Errorf(string, ...interface{})
31-
Warningf(string, ...interface{})
32-
Infof(string, ...interface{})
33-
Debugf(string, ...interface{})
34-
Tracef(string, ...interface{})
30+
Errorf(string, ...any)
31+
Warningf(string, ...any)
32+
Infof(string, ...any)
33+
Debugf(string, ...any)
34+
Tracef(string, ...any)
3535
}
3636

3737
type Option func(o *options)

internal/badgerd/pending/iterator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestIterator(t *testing.T) {
165165
assert.Equal(t, -1, i)
166166
})
167167

168-
for i := 0; i < count; i++ {
168+
for i := range count {
169169
w.Delete(initial[i].Key)
170170
}
171171

internal/badgerd/pending/wal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func newEntry(i int, size int64) *badger.Entry {
4444

4545
func genEntries(count int, size int64) []*badger.Entry {
4646
var entries []*badger.Entry
47-
for i := 0; i < count; i++ {
47+
for i := range count {
4848
entries = append(entries, newEntry(i, size))
4949
}
5050
return entries

internal/badgerd/replication/gossip/nodes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (r *Gossip) loadNodes() ([]string, error) {
295295
return nil, err
296296
}
297297
var nodes []string
298-
for _, v := range strings.Split(string(b), "\n") {
298+
for v := range strings.SplitSeq(string(b), "\n") {
299299
if v != "" && v != r.name {
300300
nodes = append(nodes, v)
301301
}

internal/badgerd/replication/gossip/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (r *Gossip) Init(req *pb2.InitRequest, ss pb2.ReplicationService_InitServer
4646
return gerrs.Internalf("failed to split host port: %v", err)
4747
}
4848
var found bool
49-
for i := 0; i < 100; i++ {
49+
for range 100 {
5050
for _, v := range r.clients() {
5151
if found = addr == v.addr.String(); found {
5252
break

internal/badgerd/replication/gossip/sync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,30 @@ func (m *Map[T]) Delete(key string) {
6767
}
6868

6969
func (m *Map[T]) Range(f func(key string, value T) bool) {
70-
m.m.Range(func(key, value interface{}) bool {
70+
m.m.Range(func(key, value any) bool {
7171
return f(key.(string), value.(T))
7272
})
7373
}
7474

7575
func (m *Map[T]) Len() int {
7676
var l int
77-
m.m.Range(func(key, value interface{}) bool {
77+
m.m.Range(func(key, value any) bool {
7878
l++
7979
return true
8080
})
8181
return l
8282
}
8383

8484
func (m *Map[T]) Clear() {
85-
m.m.Range(func(key, value interface{}) bool {
85+
m.m.Range(func(key, value any) bool {
8686
m.m.Delete(key)
8787
return true
8888
})
8989
}
9090

9191
func (m *Map[T]) Values() []T {
9292
var values []T
93-
m.m.Range(func(key, value interface{}) bool {
93+
m.m.Range(func(key, value any) bool {
9494
values = append(values, value.(T))
9595
return true
9696
})
@@ -99,7 +99,7 @@ func (m *Map[T]) Values() []T {
9999

100100
func (m *Map[T]) Keys() []string {
101101
var keys []string
102-
m.m.Range(func(key, value interface{}) bool {
102+
m.m.Range(func(key, value any) bool {
103103
keys = append(keys, key.(string))
104104
return true
105105
})

internal/badgerd/replication/gossip/tx.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"errors"
2020
"fmt"
2121
"io"
22+
"slices"
2223
"sync"
2324
"sync/atomic"
2425

@@ -87,12 +88,7 @@ func (r *tx) removeSteam(s *stream) {
8788
func (r *tx) hasStreams(s *stream) bool {
8889
r.cmu.RLock()
8990
defer r.cmu.RUnlock()
90-
for _, v := range r.cs {
91-
if v == s {
92-
return true
93-
}
94-
}
95-
return false
91+
return slices.Contains(r.cs, s)
9692
}
9793

9894
func (r *tx) New(ctx context.Context, tx *badger.Txn) error {

0 commit comments

Comments
 (0)