From 8e9db19f03a508d8cb1272ce1fe959bb5d775416 Mon Sep 17 00:00:00 2001 From: jub0bs <52325150+jub0bs@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:56:21 +0200 Subject: [PATCH] Require Go 1.23.0 or above (fixes #187) (#188) --- cors_test.go | 19 +++---------------- go.mod | 2 +- go.sum | 0 internal/sortedset.go | 18 ------------------ internal/sortedset_test.go | 11 ++--------- 5 files changed, 6 insertions(+), 44 deletions(-) delete mode 100644 go.sum diff --git a/cors_test.go b/cors_test.go index 46430fc..f537e0f 100644 --- a/cors_test.go +++ b/cors_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "regexp" + "slices" "strings" "testing" ) @@ -37,11 +38,11 @@ func assertHeaders(t *testing.T, resHeaders http.Header, expHeaders http.Header) for name, listBased := range allRespHeaders { got := resHeaders[name] want := expHeaders[name] - if !listBased && !slicesEqual(got, want) { + if !listBased && !slices.Equal(got, want) { t.Errorf("Response header %q = %q, want %q", name, got, want) continue } - if listBased && !slicesEqual(normalize(got), normalize(want)) { + if listBased && !slices.Equal(normalize(got), normalize(want)) { t.Errorf("Response header %q = %q, want %q", name, got, want) continue } @@ -60,20 +61,6 @@ func normalize(s []string) (res []string) { return } -// TODO: when updating go directive to 1.21 or later, -// use slices.Equal instead. -func slicesEqual(s1, s2 []string) bool { - if len(s1) != len(s2) { - return false - } - for i := range s1 { - if s1[i] != s2[i] { - return false - } - } - return true -} - func assertResponse(t *testing.T, res *httptest.ResponseRecorder, responseCode int) { t.Helper() if responseCode != res.Code { diff --git a/go.mod b/go.mod index dd6fac9..69d8d61 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/rs/cors -go 1.13 +go 1.23.0 diff --git a/go.sum b/go.sum deleted file mode 100644 index e69de29..0000000 diff --git a/internal/sortedset.go b/internal/sortedset.go index 844f3f9..f9a7618 100644 --- a/internal/sortedset.go +++ b/internal/sortedset.go @@ -181,21 +181,3 @@ func trimRightOWS(s string, n int) (string, bool) { } return s, true } - -// TODO: when updating go directive to 1.21 or later, -// use min builtin instead. -func min(a, b int) int { - if a < b { - return a - } - return b -} - -// TODO: when updating go directive to 1.21 or later, -// use max builtin instead. -func max(a, b int) int { - if a > b { - return a - } - return b -} diff --git a/internal/sortedset_test.go b/internal/sortedset_test.go index 1a362fc..145e318 100644 --- a/internal/sortedset_test.go +++ b/internal/sortedset_test.go @@ -1,6 +1,7 @@ package internal import ( + "slices" "strings" "testing" ) @@ -180,7 +181,7 @@ func TestSortedSet(t *testing.T) { } for _, tc := range cases { f := func(t *testing.T) { - elems := clone(tc.elems) + elems := slices.Clone(tc.elems) set := NewSortedSet(tc.elems...) size := set.Size() if set.Size() != tc.size { @@ -208,11 +209,3 @@ func TestSortedSet(t *testing.T) { t.Run(tc.desc, f) } } - -// adapted from https://pkg.go.dev/slices#Clone -// TODO: when updating go directive to 1.21 or later, -// use slices.Clone instead. -func clone(s []string) []string { - // The s[:0:0] preserves nil in case it matters. - return append(s[:0:0], s...) -}