From 920b2c45b984225a7460d17a0de24ff2b1b5adc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 4 May 2023 18:18:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9[]interface=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filter.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/filter.go b/filter.go index 426cad0..61d1b0c 100644 --- a/filter.go +++ b/filter.go @@ -176,7 +176,10 @@ func (f *filter) Parse(receiver interface{}) error { func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValue string) (interface{}, error) { sourceValueStr := defaultValue if sourceValue.Exists() { - sourceValueStr = sourceValue.String() + str := sourceValue.String() + if len(str) > 0 { + sourceValueStr = str + } } switch dataType { @@ -236,6 +239,15 @@ func (f *filter) getValue(dataType string, sourceValue gjson.Result, defaultValu return sourceValueStr, nil case DataTypeAny: return sourceValue.Value(), nil + case DataTypeAnySlice: + // 任意类型的list + var ( + result []interface{} + ) + if err := util.JSON.UnmarshalWithNumber([]byte(sourceValueStr), &result); nil != err { + return nil, err + } + return result, nil default: return nil, errors.New(dataType + " is not support!") }