升级类型枚举
This commit is contained in:
parent
45b7aea925
commit
cd52bbb02b
66
filter.go
66
filter.go
@ -10,6 +10,7 @@ package filter
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.zhangdeman.cn/zhangdeman/consts"
|
||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
||||
"strings"
|
||||
|
||||
@ -184,48 +185,33 @@ func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValu
|
||||
strVal := wrapper.String(sourceValueStr)
|
||||
|
||||
switch dataType {
|
||||
case wrapper.DataTypeInt8:
|
||||
return strVal.ToInt8().Value, strVal.ToInt8().Err
|
||||
case wrapper.DataTypeInt16:
|
||||
return strVal.ToInt16().Value, strVal.ToInt16().Err
|
||||
case wrapper.DataTypeInt32:
|
||||
return strVal.ToInt32().Value, strVal.ToInt32().Err
|
||||
case wrapper.DataTypeInt64:
|
||||
return strVal.ToInt64().Value, strVal.ToInt64().Err
|
||||
case wrapper.DataTypeInt:
|
||||
return strVal.ToInt().Value, strVal.ToInt().Err
|
||||
case wrapper.DataTypeUint8:
|
||||
return strVal.ToUint8().Value, strVal.ToUint8().Err
|
||||
case wrapper.DataTypeUint16:
|
||||
return strVal.ToUint16().Value, strVal.ToUint16().Err
|
||||
case wrapper.DataTypeUint32:
|
||||
return strVal.ToUint32().Value, strVal.ToUint32().Err
|
||||
case wrapper.DataTypeUint64:
|
||||
return strVal.ToUint64().Value, strVal.ToUint64().Err
|
||||
case wrapper.DataTypeUint:
|
||||
return strVal.ToUint().Value, strVal.ToUint().Err
|
||||
case wrapper.DataTypeBool:
|
||||
return strVal.ToBool().Value, strVal.ToBool().Err
|
||||
case wrapper.DataTypeFloat32:
|
||||
return strVal.ToFloat64().Value, strVal.ToFloat64().Err
|
||||
case wrapper.DataTypeFloat64:
|
||||
fallthrough
|
||||
case wrapper.DataTypeFloat:
|
||||
fallthrough
|
||||
case wrapper.DataTypeDouble:
|
||||
return strVal.ToFloat64().Value, strVal.ToFloat64().Err
|
||||
case wrapper.DataTypeNumber:
|
||||
return strVal.ToNumber().Value, strVal.ToNumber().Err
|
||||
case wrapper.DataTypeString:
|
||||
return sourceValueStr, nil
|
||||
case wrapper.DataTypeAny:
|
||||
return sourceValue.Value(), nil
|
||||
case wrapper.DataTypeAnySlice:
|
||||
case consts.DataTypeInt:
|
||||
intVal := strVal.ToInt()
|
||||
return intVal.Value, intVal.Err
|
||||
case consts.DataTypeUint:
|
||||
uintVal := strVal.ToUint64()
|
||||
return uintVal.Value, uintVal.Err
|
||||
case consts.DataTypeBool:
|
||||
boolVal := strVal.ToBool()
|
||||
return boolVal.Value, boolVal.Err
|
||||
case consts.DataTypeFloat:
|
||||
floatVal := strVal.ToFloat64()
|
||||
return floatVal.Value, floatVal.Err
|
||||
case consts.DataTypeString:
|
||||
return strVal.Value(), nil
|
||||
case consts.DataTypeAny:
|
||||
if sourceValue.Exists() {
|
||||
return sourceValue.Value(), nil
|
||||
}
|
||||
return defaultValue, nil
|
||||
case consts.DataTypeSliceAny:
|
||||
// 任意类型的list
|
||||
return strVal.ToAnySlice().Value, strVal.ToAnySlice().Err
|
||||
case wrapper.DataTypeObject:
|
||||
sliceVal := strVal.ToAnySlice()
|
||||
return sliceVal.Value, sliceVal.Err
|
||||
case consts.DataTypeMapStrAny:
|
||||
// object
|
||||
return strVal.ToObject().Value, strVal.ToObject().Err
|
||||
objectVal := strVal.ToObject()
|
||||
return objectVal.Value, objectVal.Err
|
||||
default:
|
||||
return nil, errors.New(dataType + " is not support!")
|
||||
}
|
||||
|
4
go.mod
4
go.mod
@ -5,10 +5,11 @@ go 1.21
|
||||
toolchain go1.21.5
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608115700-4311f44fabf6
|
||||
git.zhangdeman.cn/zhangdeman/easylock v0.0.0-20230731062340-983985c12eda
|
||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240520124754-3faebb9145e3
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240608120635-588df729e0d3
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/smartystreets/goconvey v1.8.1
|
||||
github.com/tidwall/gjson v1.17.1
|
||||
@ -17,7 +18,6 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608104035-feddc6a70f9d // indirect
|
||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 // indirect
|
||||
git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 // indirect
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -8,6 +8,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240517060653-203cc568fbec h1:ENemx9
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240517060653-203cc568fbec/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608104035-feddc6a70f9d h1:qKou2RVGqRd7ojAHq2H8xTxfwayjYvfn35Rk+Fz0+zU=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608104035-feddc6a70f9d/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608115700-4311f44fabf6 h1:3xXT341KFAN8AzliAUJtOkyTugNpHpVXY4wDXwE0xmw=
|
||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240608115700-4311f44fabf6/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||
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/easymap v0.0.0-20230307094841-e437ba87af10 h1:+Lg4vXFEiWVKjhUJdXuoP0AgjGT49oqJ3301STnZErk=
|
||||
@ -38,6 +40,8 @@ git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240320040704-e125c7e75dfb h1:B9KrV
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240320040704-e125c7e75dfb/go.mod h1:W2Dk+WLkUL6MzVS4XRKz9qZ7jfw25tqoXm04eDzGIKw=
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240520124754-3faebb9145e3 h1:fDDWQV3Xu/ntjrtKjwK30URPHr4kJJpqZocw52x+DKw=
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240520124754-3faebb9145e3/go.mod h1:7vFN7QrHLLI/iN7ZrJSU0bw/7TyaYjVQ4+clYuIoRrY=
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240608120635-588df729e0d3 h1:IDzOawDhqBWHACsPKWVv/sALUj09NxrjfB2whWaovvY=
|
||||
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20240608120635-588df729e0d3/go.mod h1:7vFN7QrHLLI/iN7ZrJSU0bw/7TyaYjVQ4+clYuIoRrY=
|
||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
|
Loading…
Reference in New Issue
Block a user