Skip to content

Commit

Permalink
chore: 最低版本提升至 go1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Oct 16, 2024
1 parent 49787b7 commit 692b4fb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
go: ['1.17.x', '1.22.x']
go: ['1.21.x', '1.23.x']

steps:

Expand Down
8 changes: 4 additions & 4 deletions cmd/fetch/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/issue9/cnregion/cmd/fetch

go 1.22.0
go 1.23.0

require (
github.com/gocolly/colly/v2 v2.1.0
github.com/issue9/cmdopt v0.13.1
github.com/issue9/cnregion/v2 v2.2023.0
github.com/issue9/errwrap v0.3.2
github.com/issue9/sliceutil v0.16.1
github.com/issue9/term/v3 v3.2.8
github.com/issue9/sliceutil v0.17.0
github.com/issue9/term/v3 v3.3.2
)

require (
Expand All @@ -24,7 +24,7 @@ require (
github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect
github.com/temoto/robotstxt v1.1.2 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions cmd/fetch/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/issue9/assert/v4 v4.3.0 h1:W3XDKmttsfzihYGxJ9rJoL2ViJgWERB9IxfHcxjv65U=
github.com/issue9/assert/v4 v4.3.0/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/assert/v4 v4.3.1 h1:dHYODk1yV7j/1baIB6K6UggI4r1Hfuljqic7PaDbwLg=
github.com/issue9/assert/v4 v4.3.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/cmdopt v0.13.1 h1:VA/Hgd92NBbZyHjZx1xcRCMhoc+XjI1LWhiuZkOZ0VU=
github.com/issue9/cmdopt v0.13.1/go.mod h1:7lnF45Ush0boi4/nDjeSDYV5lZfoOzp3jm+biJr0f4g=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
github.com/issue9/sliceutil v0.16.1 h1:NVZ2feN014oUmMpZvZUrKkKMGhAfzT8WNzJF81krebM=
github.com/issue9/sliceutil v0.16.1/go.mod h1:ldun6sT4/bOJxuMtOXhtc6P7GCwE7L+avV86HNks7qk=
github.com/issue9/term/v3 v3.2.8 h1:vAtsr9FLwrDQRyU7S8AOUI3f+QrYsXVHT/kee9MuMkk=
github.com/issue9/term/v3 v3.2.8/go.mod h1:S/xLgjEXJNr7C6UhcGTEOV5k94mzHRcYMmtvhLJoX6A=
github.com/issue9/sliceutil v0.17.0 h1:EtmVlldkAyGxS0O2TnxcAu3pgLJw74I5eh9DHT7TOZs=
github.com/issue9/sliceutil v0.17.0/go.mod h1:CVpH4f228pICY7JImlztUPe/zf2w0EicEleU9YfFe00=
github.com/issue9/term/v3 v3.3.2 h1:heyRhfA6EMztqh5UHUZyKr/LatFZXbJ7YhE5RI5fPTs=
github.com/issue9/term/v3 v3.3.2/go.mod h1:n5XiDESqvPeaLgHeG7H0JdIXU8/H5IZPEaH++0aHE5Q=
github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg=
github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o=
github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak=
Expand Down Expand Up @@ -119,8 +119,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
Expand Down
15 changes: 2 additions & 13 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"errors"
"fmt"
"slices"
"strconv"
"strings"

Expand Down Expand Up @@ -60,21 +61,9 @@ func NewDB() *DB {
// Version 当前这份数据支持的年份列表
func (db *DB) Versions() []int { return db.versions }

// 指定年份在 Versions 中的下标
//
// 如果不存在,返回 -1
func (db *DB) versionIndex(ver int) int {
for i, v := range db.versions { // TODO(go1.21) slices.IndexFunc
if v == ver {
return i
}
}
return -1
}

// AddVersion 添加新的版本号
func (db *DB) AddVersion(ver int) (ok bool) {
if db.versionIndex(ver) > -1 { // 检测 ver 是否已经存在
if slices.Index(db.versions, ver) > -1 { // 检测 ver 是否已经存在
return false
}

Expand Down
8 changes: 0 additions & 8 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,3 @@ func TestDB_Find(t *testing.T) {
Equal(r.ID(), "05").
Contains(r.Versions(), []int{2018, 2017, 2016, 2015})
}

func TestDB_versionIndex(t *testing.T) {
a := assert.New(t, false)

a.Equal(0, obj.versionIndex(2020))
a.Equal(1, obj.versionIndex(2019))
a.Equal(-1, obj.versionIndex(1990))
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/issue9/cnregion/v2

go 1.17
go 1.21

require (
github.com/issue9/assert/v4 v4.3.0
github.com/issue9/assert/v4 v4.3.1
github.com/issue9/errwrap v0.3.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/issue9/assert/v4 v4.1.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/assert/v4 v4.3.0 h1:W3XDKmttsfzihYGxJ9rJoL2ViJgWERB9IxfHcxjv65U=
github.com/issue9/assert/v4 v4.3.0/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/assert/v4 v4.3.1 h1:dHYODk1yV7j/1baIB6K6UggI4r1Hfuljqic7PaDbwLg=
github.com/issue9/assert/v4 v4.3.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
17 changes: 5 additions & 12 deletions region.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"errors"
"fmt"
"slices"
"strconv"

"github.com/issue9/errwrap"
Expand Down Expand Up @@ -41,17 +42,10 @@ func (r *Region) Versions() []int { return r.versions } // 支持的年份版
func (r *Region) Items() []*Region { return r.items } // 子项

// IsSupported 当前数据是否支持该年份
func (r *Region) IsSupported(ver int) bool {
for _, y := range r.versions { // TODO(go1.21) slices.Index
if y == ver {
return true
}
}
return false
}
func (r *Region) IsSupported(ver int) bool { return slices.Index(r.versions, ver) > -1 }

func (reg *Region) addItem(id, name string, level id.Level, ver int) error {
if index := reg.db.versionIndex(ver); index == -1 {
if slices.Index(reg.db.versions, ver) == -1 {
return fmt.Errorf("不支持该年份 %d 的数据", ver)
}

Expand All @@ -72,8 +66,7 @@ func (reg *Region) addItem(id, name string, level id.Level, ver int) error {
}

func (reg *Region) setSupported(ver int) error {
index := reg.db.versionIndex(ver)
if index == -1 {
if slices.Index(reg.db.versions, ver) == -1 {
return fmt.Errorf("不存在该年份 %d 的数据", ver)
}

Expand All @@ -100,7 +93,7 @@ func (reg *Region) findItem(regionID ...string) *Region {
func (reg *Region) marshal(buf *errwrap.Buffer) error {
supported := 0
for _, ver := range reg.versions {
index := reg.db.versionIndex(ver)
index := slices.Index(reg.db.versions, ver)
if index == -1 {
return fmt.Errorf("无效的年份 %d 位于 %s", ver, reg.fullName)
}
Expand Down

0 comments on commit 692b4fb

Please sign in to comment.