From 4828f8d80ce4b75d3d250d816080a5d5116346e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 13 Oct 2025 22:35:24 +0800 Subject: [PATCH] upgrade: update wrapper --- gjson_hack/precision.go | 35 ++++++++++++++++++----------------- go.mod | 16 ++++++++-------- go.sum | 12 ++++++++++++ 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/gjson_hack/precision.go b/gjson_hack/precision.go index 3115334..c86de36 100644 --- a/gjson_hack/precision.go +++ b/gjson_hack/precision.go @@ -9,13 +9,14 @@ package gjson_hack import ( "errors" + "strings" + "git.zhangdeman.cn/zhangdeman/consts" "git.zhangdeman.cn/zhangdeman/exception" "git.zhangdeman.cn/zhangdeman/serialize" "git.zhangdeman.cn/zhangdeman/util" - "git.zhangdeman.cn/zhangdeman/wrapper" + "git.zhangdeman.cn/zhangdeman/wrapper/op_string" "github.com/tidwall/gjson" - "strings" ) // Number 结果转换为数字(int64 / uint64 / float64) @@ -202,11 +203,11 @@ func SliceAny(gjsonResult gjson.Result) ([]any, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToAnySlice() + sliceVal := op_string.ToBaseTypeSlice[any](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToAnySlice(",") + sliceVal := op_string.ToBaseTypeSlice[any](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -223,11 +224,11 @@ func SliceInt(gjsonResult gjson.Result) ([]int64, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToInt64Slice() + sliceVal := op_string.ToBaseTypeSlice[int64](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToInt64Slice(",") + sliceVal := op_string.ToBaseTypeSlice[int64](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -245,11 +246,11 @@ func SliceUint(gjsonResult gjson.Result) ([]uint64, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToUint64Slice() + sliceVal := op_string.ToBaseTypeSlice[uint64](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToUint64Slice(",") + sliceVal := op_string.ToBaseTypeSlice[uint64](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -267,11 +268,11 @@ func SliceFloat(gjsonResult gjson.Result) ([]float64, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToFloat64Slice() + sliceVal := op_string.ToBaseTypeSlice[float64](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToFloat64Slice(",") + sliceVal := op_string.ToBaseTypeSlice[float64](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -288,11 +289,11 @@ func SliceBool(gjsonResult gjson.Result) ([]bool, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToBoolSlice() + sliceVal := op_string.ToBaseTypeSlice[bool](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToBoolSlice(",") + sliceVal := op_string.ToBaseTypeSlice[bool](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -310,11 +311,11 @@ func SliceString(gjsonResult gjson.Result) ([]string, error) { // 任意类型的list if strings.HasPrefix(strVal, "[") && strings.HasSuffix(strVal, "]") { // 序列化之后的数组 - sliceVal := wrapper.String(strVal).ToStringSlice() + sliceVal := op_string.ToBaseTypeSlice[string](strVal) return sliceVal.Value, sliceVal.Err } // 分隔的数组 - sliceVal := wrapper.String(strVal).ToStringSlice(",") + sliceVal := op_string.ToBaseTypeSlice[string](strVal, ",") return sliceVal.Value, sliceVal.Err } @@ -390,7 +391,7 @@ func Value(dataType consts.DataType, sourceValue gjson.Result, defaultValue any) // 归一化处理对象、数组等 sourceValue = Result(sourceValue) dataType = getRealDataType(dataType, sourceValue) - strVal := wrapper.String(sourceValue.String()) + strVal := sourceValue.String() switch dataType { case consts.DataTypeInt: return Int[int](sourceValue) @@ -417,7 +418,7 @@ func Value(dataType consts.DataType, sourceValue gjson.Result, defaultValue any) case consts.DataTypeFloat32: return Float[float32](sourceValue) case consts.DataTypeBool: - boolVal := strVal.ToBool() + boolVal := op_string.ToBaseTypeValue[bool](strVal) return boolVal.Value, boolVal.Err case consts.DataTypeString: return sourceValue.String(), nil @@ -426,7 +427,7 @@ func Value(dataType consts.DataType, sourceValue gjson.Result, defaultValue any) return sourceValue.Value(), nil case consts.DataTypeSliceAny: // 任意类型的list - sliceVal := strVal.ToAnySlice() + sliceVal := op_string.ToBaseTypeSlice[any](strVal) return sliceVal.Value, sliceVal.Err case consts.DataTypeSliceInt, consts.DataTypeSliceIntWithChar: // 任意类型的list diff --git a/go.mod b/go.mod index b615eb2..591256f 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,16 @@ module git.zhangdeman.cn/zhangdeman/json_filter -go 1.23.0 +go 1.24.0 toolchain go1.24.3 require ( - git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 + git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772 git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda - git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9 + git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab + git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20251013044511-86c1a4a3a9dd git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e - git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740 + git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20251013094128-d57d32b103be github.com/pkg/errors v0.9.1 github.com/smartystreets/goconvey v1.8.1 github.com/tidwall/gjson v1.18.0 @@ -18,18 +19,17 @@ require ( ) require ( - git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab // indirect - git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 // indirect + git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42 // indirect github.com/BurntSushi/toml v1.5.0 // indirect github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/jtolds/gls v4.20.0+incompatible // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect - github.com/mozillazg/go-pinyin v0.20.0 // indirect + github.com/mozillazg/go-pinyin v0.21.0 // indirect github.com/sbabiv/xml2map v1.2.1 // indirect github.com/smarty/assertions v1.15.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/match v1.2.0 // indirect github.com/tidwall/pretty v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index c55f990..8e88542 100644 --- a/go.sum +++ b/go.sum @@ -4,20 +4,28 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250328040304-7e4a6f9f148c h1:cl3gQG git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250328040304-7e4a6f9f148c/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995 h1:LmPRAf0AsxRVFPibdpZR89ajlsz8hof2IvMMyTqiEq4= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250425024726-cc17224cb995/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772 h1:Yo1ur3LnDF5s7F7tpJsNrdUSF8LwYKnN9TdQU32F3eU= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc= git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda h1:bMD6r9gjRy7cO+T4zRQVYAesgIblBdTnhzT1vN5wjvI= git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda/go.mod h1:dT0rmHcJ9Z9IqWeMIt7YzR88nKkNV2V3dfG0j9Q6lK0= git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab h1:O0XaAKKb8qrjcjewonmKfnRsMFoCfJF+tUv6RfhRe94= git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab/go.mod h1:Voc8J4ordx7nuMWpgACXXZULQy7ZIuBzcEIoS8VnDIw= git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 h1:gUDlQMuJ4xNfP2Abl1Msmpa3fASLWYkNlqDFF/6GN0Y= git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI= +git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42 h1:VjYrb4adud7FHeiYS9XA0B/tOaJjfRejzQAlwimrrDc= +git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20251013024601-da007da2fb42/go.mod h1:VHb9qmhaPDAQDcS6vUiDCamYjZ4R5lD1XtVsh55KsMI= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd h1:q7GG14qgXKB4MEXQFOe7/UYebsqMfPaSX80TcPdOosI= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20241223084948-de2e49144fcd/go.mod h1:+D6uPSljwHywjVY5WSBY4TRVMj26TN5f5cFGEYMldjs= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9 h1:/GLQaFoLb+ciHOtAS2BIyPNnf4O5ME3AC5PUaJY9kfs= git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9/go.mod h1:ABJ655C5QenQNOzf7LjCe4sSB52CXvaWLX2Zg4uwDJY= +git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20251013044511-86c1a4a3a9dd h1:kTZOpR8iHx27sUufMWVYhDZx9Q4h80j7RWlaR8GIBiU= +git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20251013044511-86c1a4a3a9dd/go.mod h1:pLrQ63JICi81/3w2BrD26QZiu+IpddvEVfMJ6No3Xb4= git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI= git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740 h1:zPUoylfJTbc0EcxW+NEzOTBmoeFZ2I/rLFBnEzxb4Wk= git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740/go.mod h1:1ct92dbVc49pmXusA/iGfcQUJzcYmJ+cjAhgc3sDv1I= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20251013094128-d57d32b103be h1:mlmXacZHRKxmFmFKNFYRjZJ8+z2+QW3CH8L7AzoMTcQ= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20251013094128-d57d32b103be/go.mod h1:mBvTwcdqHRF3QIkAh92j/JRhru2LzyJ2LBqolxjzzKE= github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ= @@ -34,6 +42,8 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mozillazg/go-pinyin v0.20.0 h1:BtR3DsxpApHfKReaPO1fCqF4pThRwH9uwvXzm+GnMFQ= github.com/mozillazg/go-pinyin v0.20.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc= +github.com/mozillazg/go-pinyin v0.21.0 h1:Wo8/NT45z7P3er/9YSLHA3/kjZzbLz5hR7i+jGeIGao= +github.com/mozillazg/go-pinyin v0.21.0/go.mod h1:iR4EnMMRXkfpFVV5FMi4FNB6wGq9NV6uDWbUuPhP4Yc= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -53,6 +63,8 @@ github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY= github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/match v1.2.0 h1:0pt8FlkOwjN2fPt4bIl4BoNxb98gGHN2ObFEDkrfZnM= +github.com/tidwall/match v1.2.0/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=