diff --git a/.github/workflows/build-tzpb.yml b/.github/workflows/build-tzpb.yml index db36350..bf922ab 100644 --- a/.github/workflows/build-tzpb.yml +++ b/.github/workflows/build-tzpb.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: ["1.21"] + go: ["1.20", "1.21"] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2808fbd..bddd0cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: name: golangci-lint strategy: matrix: - go: ["1.21"] + go: ["1.20", "1.21"] permissions: contents: read pull-requests: read @@ -50,7 +50,7 @@ jobs: build: strategy: matrix: - go: ["1.21"] + go: ["1.20", "1.21"] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/sort.go b/sort.go new file mode 100644 index 0000000..87fba39 --- /dev/null +++ b/sort.go @@ -0,0 +1,12 @@ +//go:build go1.21 + +package tzf + +import ( + "cmp" + "slices" +) + +func sort[S ~[]E, E cmp.Ordered](x S) { + slices.Sort(x) +} diff --git a/sort_before_1_21.go b/sort_before_1_21.go new file mode 100644 index 0000000..23d51e4 --- /dev/null +++ b/sort_before_1_21.go @@ -0,0 +1,11 @@ +//go:build !go1.21 + +package tzf + +import ( + "golang.org/x/exp/slices" +) + +func sort(x S) { + slices.Sort(x) +} diff --git a/tzf.go b/tzf.go index 16b4ab6..5fc12e6 100644 --- a/tzf.go +++ b/tzf.go @@ -7,7 +7,6 @@ package tzf import ( "errors" "fmt" - "slices" "github.com/ringsaturn/tzf/convert" "github.com/ringsaturn/tzf/pb" @@ -241,7 +240,7 @@ func (f *Finder) GetTimezoneNames(lng float64, lat float64) ([]string, error) { for i := 0; i < len(item); i++ { ret = append(ret, item[i].name) } - slices.Sort[[]string](ret) + sort(ret) return ret, nil } diff --git a/tzf_fuzzy.go b/tzf_fuzzy.go index e7ccd22..78e0c9c 100644 --- a/tzf_fuzzy.go +++ b/tzf_fuzzy.go @@ -1,8 +1,6 @@ package tzf import ( - "slices" - "github.com/paulmach/orb" "github.com/paulmach/orb/maptile" "github.com/ringsaturn/tzf/pb" @@ -37,7 +35,7 @@ func NewFuzzyFinderFromPB(input *pb.PreindexTimezones) (F, error) { namesMap[item.Name] = true } f.names = maps.Keys(namesMap) - slices.Sort(f.names) + sort(f.names) return f, nil }