From 3487a87104533e0639094cc4f8fa5fc4a0e39a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 5 May 2023 15:03:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- const.go | 44 -------------------------- filter.go | 93 ++++++++++++++++++++++++------------------------------- go.mod | 1 + go.sum | 4 +++ 4 files changed, 46 insertions(+), 96 deletions(-) delete mode 100644 const.go diff --git a/const.go b/const.go deleted file mode 100644 index 6474405..0000000 --- a/const.go +++ /dev/null @@ -1,44 +0,0 @@ -// Package filter ... -// -// Description : filter ... -// -// Author : go_developer@163.com<白茶清欢> -// -// Date : 2023-05-04 17:29 -package filter - -const ( - DataTypeAny = "interface" - - DataTypeString = "string" - - DataTypeInt8 = "int8" - DataTypeInt16 = "int16" - DataTypeInt32 = "int32" - DataTypeInt64 = "int64" - DataTypeInt = "int" - - DataTypeUint8 = "uint8" - DataTypeUint16 = "uint16" - DataTypeUint32 = "uint32" - DataTypeUint64 = "uint64" - DataTypeUint = "uint" - - DataTypeBool = "bool" - - DataTypeNumber = "number" - - DataTypeFloat32 = "float32" - DataTypeFloat64 = "float64" - DataTypeDouble = "double" - DataTypeFloat = "float" - - DataTypeIntSlice = "[]int" - DataTypeUntSlice = "[]uint" - DataTypeNumberSlice = "[]number" - DataTypeFloatSlice = "[]float" - DataTypeBoolSlice = "[]bool" - DataTypeAnySlice = "[]interface" - - DataTypeObject = "map[string]interface" -) diff --git a/filter.go b/filter.go index 3c2b6a8..8ca7dfe 100644 --- a/filter.go +++ b/filter.go @@ -10,14 +10,13 @@ package filter import ( "encoding/json" "fmt" + "git.zhangdeman.cn/zhangdeman/wrapper" "strings" "github.com/tidwall/gjson" "github.com/tidwall/sjson" "errors" - - "git.zhangdeman.cn/zhangdeman/util" ) // NewFilter 过滤器实例 @@ -182,61 +181,51 @@ func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValu } } + strVal := wrapper.String(sourceValueStr) + switch dataType { - case DataTypeInt8: - return util.StringConvert.ToInt8(sourceValueStr) - case DataTypeInt16: - return util.StringConvert.ToInt16(sourceValueStr) - case DataTypeInt32: - return util.StringConvert.ToInt32(sourceValueStr) - case DataTypeInt64: - return util.StringConvert.ToInt64(sourceValueStr) - case DataTypeInt: - return util.StringConvert.ToInt(sourceValueStr) - case DataTypeUint8: - return util.StringConvert.ToUint8(sourceValueStr) - case DataTypeUint16: - return util.StringConvert.ToUint16(sourceValueStr) - case DataTypeUint32: - return util.StringConvert.ToUint32(sourceValueStr) - case DataTypeUint64: - return util.StringConvert.ToUint64(sourceValueStr) - case DataTypeUint: - return util.StringConvert.ToUint(sourceValueStr) - case DataTypeBool: - return util.StringConvert.ToBool(sourceValueStr) - case DataTypeFloat32: - return util.StringConvert.ToFloat32(sourceValueStr) - case DataTypeFloat64: - return util.StringConvert.ToFloat64(sourceValueStr) - case DataTypeFloat: - return util.StringConvert.ToFloat64(sourceValueStr) - case DataTypeDouble: - return util.StringConvert.ToDouble(sourceValueStr) - case DataTypeNumber: - return util.StringConvert.ToNumber(sourceValueStr) - case DataTypeString: + case wrapper.DataTypeInt8: + return strVal.ToInt8() + case wrapper.DataTypeInt16: + return strVal.ToInt16() + case wrapper.DataTypeInt32: + return strVal.ToInt32() + case wrapper.DataTypeInt64: + return strVal.ToInt64() + case wrapper.DataTypeInt: + return strVal.ToInt() + case wrapper.DataTypeUint8: + return strVal.ToUint8() + case wrapper.DataTypeUint16: + return strVal.ToUint16() + case wrapper.DataTypeUint32: + return strVal.ToUint32() + case wrapper.DataTypeUint64: + return strVal.ToUint64() + case wrapper.DataTypeUint: + return strVal.ToUint() + case wrapper.DataTypeBool: + return strVal.ToBool() + case wrapper.DataTypeFloat32: + return strVal.ToFloat64() + case wrapper.DataTypeFloat64: + fallthrough + case wrapper.DataTypeFloat: + fallthrough + case wrapper.DataTypeDouble: + return strVal.ToFloat64() + case wrapper.DataTypeNumber: + return strVal.ToNumber() + case wrapper.DataTypeString: return sourceValueStr, nil - case DataTypeAny: + case wrapper.DataTypeAny: return sourceValue.Value(), nil - case DataTypeAnySlice: + case wrapper.DataTypeAnySlice: // 任意类型的list - var ( - result []interface{} - ) - if err := util.JSON.UnmarshalWithNumber([]byte(sourceValueStr), &result); nil != err { - return nil, err - } - return result, nil - case DataTypeObject: + return strVal.ToAnySlice() + case wrapper.DataTypeObject: // object - var ( - result map[string]interface{} - ) - if err := util.JSON.UnmarshalWithNumber([]byte(sourceValueStr), &result); nil != err { - return nil, err - } - return result, nil + return strVal.ToObject() default: return nil, errors.New(dataType + " is not support!") } diff --git a/go.mod b/go.mod index c3b6d01..66bca94 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( ) require ( + git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230505070245-b182b21e039b // indirect github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect diff --git a/go.sum b/go.sum index 571448e..946bac3 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,10 @@ git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330082619-662152cb682d h1:kMQZmkYB git.zhangdeman.cn/zhangdeman/util v0.0.0-20230330082619-662152cb682d/go.mod h1:qeVsrMae8ljqzcsmI+lWPU/4Rdjb9cOt4oaDUNEf1Ck= git.zhangdeman.cn/zhangdeman/util v0.0.0-20230505025924-96532aff0019 h1:eJ/9rEj2iI8P9I1DfCmMUvsV+n2EiAWCXnI9yVVDHO0= git.zhangdeman.cn/zhangdeman/util v0.0.0-20230505025924-96532aff0019/go.mod h1:z2bP5LIwRVpWSQV0/a3WIFaoarJUP8kA/0Clv0bP+8I= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230505064614-5e785171ed67 h1:DH9K3fNddpFxRGLkcLP5MHsAQVinpWpmGzbVBf8yrKM= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230505064614-5e785171ed67/go.mod h1:2jc48WuVoHxZjkvlBewzp+ey8khP1K4OOcibVD1yL2k= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230505070245-b182b21e039b h1:ZwAA10/+v3FFAq5/EzjXdXDodmKppXb5gBkCcgaYVBo= +git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20230505070245-b182b21e039b/go.mod h1:2jc48WuVoHxZjkvlBewzp+ey8khP1K4OOcibVD1yL2k= github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo= github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= github.com/axgle/mahonia v0.0.0-20180208002826-3358181d7394 h1:OYA+5W64v3OgClL+IrOD63t4i/RW7RqrAVl9LTZ9UqQ=