From 6ba8959a8adb25806024c66987f8bc90870737a8 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Wed, 2 Aug 2023 20:54:13 +0200 Subject: [PATCH] Fix removal of maps.Keys in go1.21rc4 --- cmd/api/api.go | 3 +-- cmd/web/web.go | 3 +-- utils/maps.go | 9 +++++++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 utils/maps.go diff --git a/cmd/api/api.go b/cmd/api/api.go index 9dab0f9..e93e519 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -21,7 +21,6 @@ import ( "github.com/gorilla/mux" "io" "log" - "maps" "math" "net/http" _ "net/http/pprof" @@ -1556,7 +1555,7 @@ func main() { } } - sortedAddresses := maps.Keys(addresses) + sortedAddresses := utils.Keys(addresses) //Sort based on addresses slices.SortFunc(sortedAddresses, func(a address.PackedAddress, b address.PackedAddress) int { diff --git a/cmd/web/web.go b/cmd/web/web.go index 8188a54..07afac4 100644 --- a/cmd/web/web.go +++ b/cmd/web/web.go @@ -18,7 +18,6 @@ import ( "github.com/valyala/quicktemplate" "io" "log" - "maps" "math" "net/http" _ "net/http/pprof" @@ -722,7 +721,7 @@ func main() { } } - minerKeys := maps.Keys(miners) + minerKeys := utils.Keys(miners) slices.SortFunc(minerKeys, func(a uint64, b uint64) int { return miners[a].Weight.Cmp(miners[b].Weight) * -1 }) diff --git a/utils/maps.go b/utils/maps.go new file mode 100644 index 0000000..4f468fb --- /dev/null +++ b/utils/maps.go @@ -0,0 +1,9 @@ +package utils + +func Keys[M ~map[K]V, K comparable, V any](m M) []K { + r := make([]K, 0, len(m)) + for k := range m { + r = append(r, k) + } + return r +}