diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5b80bbd..e5fed27 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/doc.go b/doc.go index 294069f..aa78f69 100644 --- a/doc.go +++ b/doc.go @@ -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 diff --git a/go.mod b/go.mod index 1bd52c6..7c5ac09 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 2ba59f3..55b7465 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/obj.go b/obj.go index 7f07cc3..ce39599 100644 --- a/obj.go +++ b/obj.go @@ -16,7 +16,7 @@ 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 { // 如果是指针,则获取指向的对象 @@ -24,7 +24,7 @@ func obj2Map(obj any, maps map[string]any, conv FieldConvert) error { } if objVal.Kind() != reflect.Struct { - return typeError(obj, "map[string]interface{}") + return typeError(obj, "map[string]any") } objType := objVal.Type() @@ -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) diff --git a/value.go b/value.go index 0aa8402..24a023c 100644 --- a/value.go +++ b/value.go @@ -12,7 +12,7 @@ import ( // // 如果 source 为 nil,则会将 target 的值设置为其默认的零值。 // -// 若类型不能直接转换,会尝试其它种方式转换,比如 strconv.ParseInt() 等。 +// 若类型不能直接转换,会尝试其它种方式转换,比如 [strconv.ParseInt] 等。 func Value(source any, target reflect.Value) error { kind := target.Kind() diff --git a/value_test.go b/value_test.go index 516af78..f82e0e0 100644 --- a/value_test.go +++ b/value_test.go @@ -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)