Skip to content

Commit

Permalink
Require Go 1.23.0 or above (fixes #187) (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
jub0bs committed Aug 30, 2024
1 parent a814d79 commit 8e9db19
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 44 deletions.
19 changes: 3 additions & 16 deletions cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"regexp"
"slices"
"strings"
"testing"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/rs/cors

go 1.13
go 1.23.0

Check failure on line 3 in go.mod

View workflow job for this annotation

GitHub Actions / test (1.17)

invalid go version '1.23.0': must match format 1.23
Empty file removed go.sum
Empty file.
18 changes: 0 additions & 18 deletions internal/sortedset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 2 additions & 9 deletions internal/sortedset_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal

import (
"slices"
"strings"
"testing"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
}

0 comments on commit 8e9db19

Please sign in to comment.