Skip to content

Commit 8e9db19

Browse files
authored
Require Go 1.23.0 or above (fixes #187) (#188)
1 parent a814d79 commit 8e9db19

File tree

5 files changed

+6
-44
lines changed

5 files changed

+6
-44
lines changed

cors_test.go

+3-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"net/http/httptest"
88
"regexp"
9+
"slices"
910
"strings"
1011
"testing"
1112
)
@@ -37,11 +38,11 @@ func assertHeaders(t *testing.T, resHeaders http.Header, expHeaders http.Header)
3738
for name, listBased := range allRespHeaders {
3839
got := resHeaders[name]
3940
want := expHeaders[name]
40-
if !listBased && !slicesEqual(got, want) {
41+
if !listBased && !slices.Equal(got, want) {
4142
t.Errorf("Response header %q = %q, want %q", name, got, want)
4243
continue
4344
}
44-
if listBased && !slicesEqual(normalize(got), normalize(want)) {
45+
if listBased && !slices.Equal(normalize(got), normalize(want)) {
4546
t.Errorf("Response header %q = %q, want %q", name, got, want)
4647
continue
4748
}
@@ -60,20 +61,6 @@ func normalize(s []string) (res []string) {
6061
return
6162
}
6263

63-
// TODO: when updating go directive to 1.21 or later,
64-
// use slices.Equal instead.
65-
func slicesEqual(s1, s2 []string) bool {
66-
if len(s1) != len(s2) {
67-
return false
68-
}
69-
for i := range s1 {
70-
if s1[i] != s2[i] {
71-
return false
72-
}
73-
}
74-
return true
75-
}
76-
7764
func assertResponse(t *testing.T, res *httptest.ResponseRecorder, responseCode int) {
7865
t.Helper()
7966
if responseCode != res.Code {

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/rs/cors
22

3-
go 1.13
3+
go 1.23.0

go.sum

Whitespace-only changes.

internal/sortedset.go

-18
Original file line numberDiff line numberDiff line change
@@ -181,21 +181,3 @@ func trimRightOWS(s string, n int) (string, bool) {
181181
}
182182
return s, true
183183
}
184-
185-
// TODO: when updating go directive to 1.21 or later,
186-
// use min builtin instead.
187-
func min(a, b int) int {
188-
if a < b {
189-
return a
190-
}
191-
return b
192-
}
193-
194-
// TODO: when updating go directive to 1.21 or later,
195-
// use max builtin instead.
196-
func max(a, b int) int {
197-
if a > b {
198-
return a
199-
}
200-
return b
201-
}

internal/sortedset_test.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package internal
22

33
import (
4+
"slices"
45
"strings"
56
"testing"
67
)
@@ -180,7 +181,7 @@ func TestSortedSet(t *testing.T) {
180181
}
181182
for _, tc := range cases {
182183
f := func(t *testing.T) {
183-
elems := clone(tc.elems)
184+
elems := slices.Clone(tc.elems)
184185
set := NewSortedSet(tc.elems...)
185186
size := set.Size()
186187
if set.Size() != tc.size {
@@ -208,11 +209,3 @@ func TestSortedSet(t *testing.T) {
208209
t.Run(tc.desc, f)
209210
}
210211
}
211-
212-
// adapted from https://pkg.go.dev/slices#Clone
213-
// TODO: when updating go directive to 1.21 or later,
214-
// use slices.Clone instead.
215-
func clone(s []string) []string {
216-
// The s[:0:0] preserves nil in case it matters.
217-
return append(s[:0:0], s...)
218-
}

0 commit comments

Comments
 (0)