Skip to content

Commit 6ac72be

Browse files
authored
Merge pull request #705 from Juneezee/refactor/exp
Replace `golang.org/x/exp` with stdlib
2 parents 4824f2d + 25cf6df commit 6ac72be

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

edge-apis/pool.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/michaelquigley/pfxlog"
2222
cmap "github.com/orcaman/concurrent-map/v2"
2323
errors "github.com/pkg/errors"
24-
"golang.org/x/exp/rand"
24+
"math/rand/v2"
2525
"net"
2626
"net/url"
2727
"sync/atomic"
@@ -223,7 +223,6 @@ func (c *ClientTransportPoolRandom) TryTransportForF(cb func(*ApiClientTransport
223223
}
224224

225225
func (c *ClientTransportPoolRandom) AnyTransport() *ApiClientTransport {
226-
rand.Seed(uint64(time.Now().UnixNano()))
227226
transportBuffer := c.pool.Items()
228227
var keys []string
229228

@@ -234,7 +233,9 @@ func (c *ClientTransportPoolRandom) AnyTransport() *ApiClientTransport {
234233
if len(keys) == 0 {
235234
return nil
236235
}
237-
index := rand.Intn(len(keys))
236+
seed := uint64(time.Now().UnixNano())
237+
rng := rand.New(rand.NewPCG(seed, seed))
238+
index := rng.IntN(len(keys))
238239
return transportBuffer[keys[index]]
239240
}
240241

@@ -257,11 +258,12 @@ func errorIndicatesControllerSwap(err error) bool {
257258
}
258259

259260
func selectAndRemoveRandom[T any](slice []T, zero T) (selected T, modifiedSlice []T) {
260-
rand.Seed(uint64(time.Now().UnixNano()))
261261
if len(slice) == 0 {
262262
return zero, slice
263263
}
264-
index := rand.Intn(len(slice))
264+
seed := uint64(time.Now().UnixNano())
265+
rng := rand.New(rand.NewPCG(seed, seed))
266+
index := rng.IntN(len(slice))
265267
selected = slice[index]
266268
modifiedSlice = append(slice[:index], slice[index+1:]...)
267269
return selected, modifiedSlice

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ require (
3232
github.com/stretchr/testify v1.10.0
3333
github.com/zitadel/oidc/v2 v2.12.2
3434
go.mozilla.org/pkcs7 v0.9.0
35-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
3635
golang.org/x/oauth2 v0.28.0
3736
golang.org/x/sys v0.31.0
3837
google.golang.org/protobuf v1.36.6

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
430430
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
431431
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
432432
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
433-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
434-
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc=
435433
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
436434
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
437435
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=

ziti/edge/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/mitchellh/mapstructure"
77
"github.com/openziti/edge-api/rest_model"
88
"github.com/pkg/errors"
9-
"golang.org/x/exp/slices"
109
"net"
10+
"slices"
1111
"strings"
1212
)
1313

0 commit comments

Comments
 (0)