优化error
This commit is contained in:
19
filter.go
19
filter.go
@ -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!")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user