From 735c0d910395c9e397bbdde5edac96d8f7bfcf18 Mon Sep 17 00:00:00 2001 From: Deluan Date: Wed, 31 Dec 2025 17:02:52 -0500 Subject: [PATCH] chore(deps): remove direct dependency on golang.org/x/exp Signed-off-by: Deluan --- go.mod | 2 +- utils/number/number.go | 10 +++++++--- utils/random/number.go | 4 ++-- utils/slice/slice.go | 7 ++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index a7d14c1d7..3f49496bc 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,6 @@ require ( github.com/unrolled/secure v1.17.0 github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 go.uber.org/goleak v1.3.0 - golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 golang.org/x/image v0.34.0 golang.org/x/net v0.48.0 golang.org/x/sync v0.19.0 @@ -130,6 +129,7 @@ require ( go.yaml.in/yaml/v2 v2.4.2 // indirect go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/crypto v0.46.0 // indirect + golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect golang.org/x/mod v0.31.0 // indirect golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc // indirect golang.org/x/tools v0.40.0 // indirect diff --git a/utils/number/number.go b/utils/number/number.go index 5176a83e4..daf3b4deb 100644 --- a/utils/number/number.go +++ b/utils/number/number.go @@ -2,11 +2,15 @@ package number import ( "strconv" - - "golang.org/x/exp/constraints" ) -func ParseInt[T constraints.Integer](s string) T { +// Integer is a constraint that permits any integer type. +type Integer interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | + ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr +} + +func ParseInt[T Integer](s string) T { r, _ := strconv.ParseInt(s, 10, 64) return T(r) } diff --git a/utils/random/number.go b/utils/random/number.go index 80c242c38..e93344c19 100644 --- a/utils/random/number.go +++ b/utils/random/number.go @@ -5,12 +5,12 @@ import ( "encoding/binary" "math/big" - "golang.org/x/exp/constraints" + "github.com/navidrome/navidrome/utils/number" ) // Int64N returns a random int64 between 0 and max. // This is a reimplementation of math/rand/v2.Int64N using a cryptographically secure random number generator. -func Int64N[T constraints.Integer](max T) int64 { +func Int64N[T number.Integer](max T) int64 { rnd, _ := rand.Int(rand.Reader, big.NewInt(int64(max))) return rnd.Int64() } diff --git a/utils/slice/slice.go b/utils/slice/slice.go index b1f50afcc..e87ac5388 100644 --- a/utils/slice/slice.go +++ b/utils/slice/slice.go @@ -6,9 +6,8 @@ import ( "cmp" "io" "iter" + "maps" "slices" - - "golang.org/x/exp/maps" ) func Map[T any, R any](t []T, mapFunc func(T) R) []R { @@ -49,11 +48,9 @@ func CompactByFrequency[T comparable](list []T) []T { counters[item]++ } - sorted := maps.Keys(counters) - slices.SortFunc(sorted, func(i, j T) int { + return slices.SortedFunc(maps.Keys(counters), func(i, j T) int { return cmp.Compare(counters[j], counters[i]) }) - return sorted } func MostFrequent[T comparable](list []T) T {