Skip to content

Commit

Permalink
ci: 支持 go1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Feb 22, 2024
1 parent f6a2069 commit ec54b90
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
go: ['1.18.x', '1.20.x']
go: ['1.18.x', '1.22.x']

steps:

- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
Expand Down
11 changes: 6 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// Package conv 提供了基础的类型转换功能
//
// 会尽最大可能地将当前的值转换成指定类型的值。
// conv.MustInt("123", 0) // 返回 123 的数值
// conv.MustString(123, "")// 返回字符串 123
// conv.Int("123", 0) // 返回 123 数值和 nil 的 error 接口
// v := 5
// conv.Value("3", reflect.ValueOf(v)) // 将 3 转换成数值,并写入 v 中。
//
// conv.MustInt("123", 0) // 返回 123 的数值
// conv.MustString(123, "")// 返回字符串 123
// conv.Int("123", 0) // 返回 123 数值和 nil 的 error 接口
// v := 5
// conv.Value("3", reflect.ValueOf(v)) // 将 3 转换成数值,并写入 v 中。
package conv
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/issue9/conv

require github.com/issue9/assert/v3 v3.0.4
require github.com/issue9/assert/v3 v3.1.0

go 1.18
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/issue9/assert/v3 v3.0.4 h1:WsYZQ6PQmM/pGFrbkn5GIXjWeVZHv+wcl2829UTX1Qc=
github.com/issue9/assert/v3 v3.0.4/go.mod h1:yft/uaskRpwQTyBT3n1zRl91SR1wNlO4fLZHzOa4bdM=
github.com/issue9/assert/v3 v3.1.0 h1:oxLFXS7QnBKI4lB31pRoYO96yErkWAJtR7iv+LNjAPg=
github.com/issue9/assert/v3 v3.1.0/go.mod h1:yft/uaskRpwQTyBT3n1zRl91SR1wNlO4fLZHzOa4bdM=
6 changes: 3 additions & 3 deletions obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ type FieldConvert func(src string) (dest string)
// FieldConvert 的默认实现
func defaultFieldConvert(src string) string { return src }

// 将 obj 对象转换成 map[string]interface{} 格式的数据
// 将 obj 对象转换成 map[string]any 格式的数据
func obj2Map(obj any, maps map[string]any, conv FieldConvert) error {
objVal := reflect.ValueOf(obj)
for objVal.Kind() == reflect.Ptr { // 如果是指针,则获取指向的对象
objVal = objVal.Elem()
}

if objVal.Kind() != reflect.Struct {
return typeError(obj, "map[string]interface{}")
return typeError(obj, "map[string]any")
}

objType := objVal.Type()
Expand Down Expand Up @@ -83,7 +83,7 @@ func Map2Obj(src any, dest any, conv FieldConvert) error {
k := keys[i]

if k.Kind() != reflect.String {
return errors.New("conv: src 必须为 map[string]interface{} 类型")
return errors.New("conv: src 必须为 map[string]any 类型")
}

srcItemVal := srcVal.MapIndex(k)
Expand Down
2 changes: 1 addition & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
//
// 如果 source 为 nil,则会将 target 的值设置为其默认的零值。
//
// 若类型不能直接转换,会尝试其它种方式转换,比如 strconv.ParseInt() 等。
// 若类型不能直接转换,会尝试其它种方式转换,比如 [strconv.ParseInt] 等。
func Value(source any, target reflect.Value) error {
kind := target.Kind()

Expand Down
3 changes: 1 addition & 2 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func TestValue(t *testing.T) {
a.NotError(Value(s9, reflect.ValueOf(&t9)))
a.Equal(49, t9)

var s10 any
s10 = '1'
var s10 any = '1'
t10 := int('2')
a.NotError(Value(s10, reflect.ValueOf(&t10)))
a.Equal(49, t10)
Expand Down

0 comments on commit ec54b90

Please sign in to comment.