增加[][]any处理
This commit is contained in:
parent
9c7886dec3
commit
93117e13ea
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.zhangdeman.cn/gateway/validator
|
|||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501132050-6c507d6b9c99 // indirect
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501142503-e31a270e50cc // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 // indirect
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 // indirect
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 // indirect
|
||||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253 // indirect
|
git.zhangdeman.cn/zhangdeman/util v0.0.0-20231227095334-7eb5cdbf9253 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -8,6 +8,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240430135109-0be82b4a6434 h1:BgpbeE
|
|||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240430135109-0be82b4a6434/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240430135109-0be82b4a6434/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501132050-6c507d6b9c99 h1:rskqw1MOJ7b2qvGZLJ8S9POZFqvcaeaCnBp4FStIiyI=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501132050-6c507d6b9c99 h1:rskqw1MOJ7b2qvGZLJ8S9POZFqvcaeaCnBp4FStIiyI=
|
||||||
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501132050-6c507d6b9c99/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501132050-6c507d6b9c99/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501142503-e31a270e50cc h1:kPz9xiUVruM8kwbUUVpxyCTX8pGgyKt60K5zX77oyC4=
|
||||||
|
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240501142503-e31a270e50cc/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=
|
||||||
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U=
|
||||||
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQcGqdzi4UdpZlp4f4FUPeBqoygP58pEKJkmN3ROsE0=
|
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240325080031-1f58204e8687 h1:uQcGqdzi4UdpZlp4f4FUPeBqoygP58pEKJkmN3ROsE0=
|
||||||
|
13
run.go
13
run.go
@ -180,6 +180,8 @@ func handleData(inputVal any, rule *define.FieldRule) (any, error) {
|
|||||||
return handleSliceFloat(inputVal, rule)
|
return handleSliceFloat(inputVal, rule)
|
||||||
case consts.DataTypeSliceBool, consts.DataTypeSliceBoolWithChar: // bool数组
|
case consts.DataTypeSliceBool, consts.DataTypeSliceBoolWithChar: // bool数组
|
||||||
return handleSliceBool(inputVal, rule)
|
return handleSliceBool(inputVal, rule)
|
||||||
|
case consts.DataTypeSliceSlice:
|
||||||
|
return handleSliceSlice(inputVal, rule)
|
||||||
case consts.DataTypeSliceMapAnyAny: // map 列表
|
case consts.DataTypeSliceMapAnyAny: // map 列表
|
||||||
return handleSliceMapAny(inputVal, rule)
|
return handleSliceMapAny(inputVal, rule)
|
||||||
case consts.DataTypeSliceMapStringAny:
|
case consts.DataTypeSliceMapStringAny:
|
||||||
@ -584,7 +586,16 @@ func handleSliceSlice(inputValue interface{}, rule *define.FieldRule) ([][]any,
|
|||||||
if anySlice, err = handleSlice(inputValue, rule); nil != err {
|
if anySlice, err = handleSlice(inputValue, rule); nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil, nil
|
sliceSlice := make([][]any, 0)
|
||||||
|
for _, item := range anySlice {
|
||||||
|
byteData := serialize.JSON.MarshalForByte(item)
|
||||||
|
res := make([]any, 0)
|
||||||
|
if err = serialize.JSON.UnmarshalWithNumber(byteData, &res); nil != err {
|
||||||
|
return nil, fmt.Errorf("%v : data type is expect [][]any, but convert fail : %v", rule.Path, err.Error())
|
||||||
|
}
|
||||||
|
sliceSlice = append(sliceSlice, res)
|
||||||
|
}
|
||||||
|
return sliceSlice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleSliceMapAny ...
|
// handleSliceMapAny ...
|
||||||
|
Loading…
Reference in New Issue
Block a user