upgrade: update wrapper
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user