Skip to content

Commit

Permalink
Replace golang.org/x/exp with stdlib
Browse files Browse the repository at this point in the history
These experimental packages are now available in the Go standard
library since Go 1.21.

	1. golang.org/x/exp/slices -> slices [1]
	2. golang.org/x/exp/maps -> maps [2]
	3. golang.org/x/exp/constraints -> cmp [3]

[1]: https://go.dev/doc/go1.21#slices
[2]: https://go.dev/doc/go1.21#maps
[3]: https://go.dev/doc/go1.21#cmp

Signed-off-by: Eng Zer Jun <[email protected]>
  • Loading branch information
Juneezee committed Feb 4, 2025
1 parent 0550d8d commit f43a52a
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 17 deletions.
1 change: 0 additions & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ following Free and Open Source software:
go.opentelemetry.io/otel/metric v1.34.0 Apache License 2.0
go.opentelemetry.io/otel/trace v1.34.0 Apache License 2.0
golang.org/x/crypto v0.32.0 3-clause BSD license
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 3-clause BSD license
golang.org/x/mod v0.22.0 3-clause BSD license
golang.org/x/net v0.34.0 3-clause BSD license
golang.org/x/oauth2 v0.25.0 3-clause BSD license
Expand Down
3 changes: 1 addition & 2 deletions cmd/traffic/cmd/manager/cluster/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"context"
"fmt"
"net"
"slices"
"sync"

"golang.org/x/exp/slices"

rpc "github.com/telepresenceio/telepresence/rpc/v2/manager"
)

Expand Down
5 changes: 2 additions & 3 deletions cmd/traffic/cmd/manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package manager
import (
"context"
"fmt"
"maps"
"net/netip"
"slices"
"sort"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/blang/semver/v4"
"github.com/google/uuid"
dns2 "github.com/miekg/dns"
"golang.org/x/exp/maps"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -414,8 +414,7 @@ func (s *service) watchAgents(ctx context.Context, includeAgent func(string, *rp
dlog.Debug(ctx, "WatchAgentsNS request cancelled")
return nil
}
agentSessionIDs := maps.Keys(snapshot.State)
sort.Strings(agentSessionIDs)
agentSessionIDs := slices.Sorted(maps.Keys(snapshot.State))
agents := make([]*rpc.AgentInfo, len(agentSessionIDs))
for i, agentSessionID := range agentSessionIDs {
agents[i] = snapshot.State[agentSessionID]
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
github.com/telepresenceio/go-fuseftp/rpc v0.5.0
github.com/telepresenceio/telepresence/rpc/v2 v2.21.1
github.com/vishvananda/netlink v1.3.0
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
golang.org/x/net v0.34.0
golang.org/x/sys v0.29.0
golang.org/x/term v0.28.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
Expand Down
3 changes: 1 addition & 2 deletions pkg/client/rootd/vip/env_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package vip

import (
"context"
"maps"
"net/netip"
"testing"

"golang.org/x/exp/maps"

"github.com/datawire/dlib/dlog"
)

Expand Down
5 changes: 2 additions & 3 deletions pkg/maps/utils.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package maps

import (
"cmp"
"sort"

"golang.org/x/exp/constraints"
)

// Copy creates a copy of the given map and returns it.
Expand Down Expand Up @@ -36,7 +35,7 @@ func Merge[K comparable, V any](dst, src map[K]V) {
}

// ToSortedSlice returns a slice of the values in the given map, sorted by that map's keys.
func ToSortedSlice[K constraints.Ordered, V any](m map[K]V) []V {
func ToSortedSlice[K cmp.Ordered, V any](m map[K]V) []V {
ns := make([]K, len(m))
i := 0
for n := range m {
Expand Down
1 change: 0 additions & 1 deletion pkg/vif/testdata/router/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ require (
github.com/vishvananda/netns v0.0.5 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/sync v0.10.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions pkg/vif/testdata/router/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down

0 comments on commit f43a52a

Please sign in to comment.