Skip to content

Commit 22889c1

Browse files
authored
refactor: apply go fix modernizers from Go 1.26 (#133)
This PR applies automated refactoring from go 1.26 (go fix ./...): interface{} to any, slices.Contains, range loops and other idiomatic updates.
1 parent 546e779 commit 22889c1

5 files changed

Lines changed: 7 additions & 10 deletions

File tree

autoconf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ func normalizeEndpointURL(url, expectedPath, flagName string) (string, error) {
8282
}
8383

8484
// Check if URL has the expected routing path
85-
if strings.HasSuffix(url, expectedPath) {
85+
if before, ok := strings.CutSuffix(url, expectedPath); ok {
8686
// Strip the expected path to get base URL
87-
return strings.TrimSuffix(url, expectedPath), nil
87+
return before, nil
8888
}
8989

9090
// Check if URL has a different routing path (potential misconfiguration)

cached_addr_book.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func newCachedAddrBook(opts ...AddrBookOption) (*cachedAddrBook, error) {
147147
}
148148

149149
func (cab *cachedAddrBook) background(ctx context.Context, host host.Host) {
150-
sub, err := host.EventBus().Subscribe([]interface{}{
150+
sub, err := host.EventBus().Subscribe([]any{
151151
&event.EvtPeerIdentificationCompleted{},
152152
&event.EvtPeerConnectednessChanged{},
153153
})

cached_addr_book_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ func TestBackground(t *testing.T) {
7878
}
7979

8080
func TestProbePeers(t *testing.T) {
81-
ctx, cancel := context.WithCancel(context.Background())
82-
defer cancel()
81+
ctx := t.Context()
8382

8483
// Create a test libp2p host
8584
mockHost := &mockHost{}

server_dht_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func makePeerRecords(t *testing.T, count int) ([]iter.Result[*types.PeerRecord],
5050
var peerRecords []iter.Result[*types.PeerRecord]
5151
var peerIDs []peer.ID
5252

53-
for i := 0; i < count; i++ {
53+
for i := range count {
5454
_, p := makeEd25519PeerID(t)
5555
peerIDs = append(peerIDs, p)
5656

server_routers_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ func TestManyIter(t *testing.T) {
596596
t.Run("Sequence", func(t *testing.T) {
597597
t.Parallel()
598598

599-
ctx, cancel := context.WithCancel(context.Background())
600-
defer cancel()
599+
ctx := t.Context()
601600

602601
its := newMockIters[int](ctx, 2)
603602
manyIter := newManyIter(ctx, mockItersAsInterface(its))
@@ -632,8 +631,7 @@ func TestManyIter(t *testing.T) {
632631
t.Run("Closed Iterator", func(t *testing.T) {
633632
t.Parallel()
634633

635-
ctx, cancel := context.WithCancel(context.Background())
636-
defer cancel()
634+
ctx := t.Context()
637635

638636
its := newMockIters[int](ctx, 5)
639637
manyIter := newManyIter(ctx, mockItersAsInterface(its))

0 commit comments

Comments
 (0)