feature/upgrade_filter #7

Merged
zhangdeman merged 14 commits from feature/upgrade_filter into master 2024-12-02 14:35:30 +08:00
2 changed files with 24 additions and 9 deletions
Showing only changes of commit 8cca556d6f - Show all commits

14
error.go Normal file
View File

@ -0,0 +1,14 @@
// Package filter ...
//
// Description : filter ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-11-30 19:14
package filter
import "errors"
var (
ErrDataIsNotObject = errors.New("data is not an object")
)

View File

@ -242,6 +242,7 @@ func (f *filter) getValue(dataType consts.DataType, sourceValue gjson.Result, de
return strVal.Value(), nil
case consts.DataTypeAny:
if sourceValue.Exists() {
// TODO : 可能存在精度丢失
return sourceValue.Value(), nil
}
return defaultValue, nil
@ -251,7 +252,7 @@ func (f *filter) getValue(dataType consts.DataType, sourceValue gjson.Result, de
return sliceVal.Value, sliceVal.Err
case consts.DataTypeSliceInt, consts.DataTypeSliceIntWithChar:
// 任意类型的list
if strings.HasPrefix(strVal.Value(), "[") && strings.HasPrefix(strVal.Value(), "]") {
if strings.HasPrefix(strVal.Value(), "[") && strings.HasSuffix(strVal.Value(), "]") {
// 序列化之后的数组
sliceVal := strVal.ToInt64Slice()
return sliceVal.Value, sliceVal.Err
@ -310,54 +311,54 @@ func (f *filter) getValue(dataType consts.DataType, sourceValue gjson.Result, de
return res, err
case consts.DataTypeMapStrInt:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]int64
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrUint:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]uint64
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrFloat:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]float64
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrBool:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]bool
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrAny:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]any
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrStr:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string]string
err := strVal.ToStruct(&res)
return res, err
case consts.DataTypeMapStrSlice:
if !sourceValue.IsObject() {
return nil, errors.New("data type is not object")
return nil, ErrDataIsNotObject
}
var res map[string][]any
err := strVal.ToStruct(&res)
return res, err
default:
return nil, errors.New(dataType.String() + " is not support!")
return nil, errors.New("`" + dataType.String() + "` is not support!")
}
}