diff --git a/error.go b/error.go new file mode 100644 index 0000000..6896b95 --- /dev/null +++ b/error.go @@ -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") +) diff --git a/filter.go b/filter.go index f8c92f1..3e59717 100644 --- a/filter.go +++ b/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!") } }