From 67abdaeb7da5fe2535595a408b75a5d485cb04fa 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, 16 May 2024 21:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96handleSliceString?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handle_slice.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/handle_slice.go b/handle_slice.go index 68db15e..d80661b 100644 --- a/handle_slice.go +++ b/handle_slice.go @@ -245,11 +245,11 @@ func handleSliceString(inputStr string, rule *define.FieldRule) ([]any, error) { if rule.SliceConfig.Mode == consts.DataSliceModelReal { return nil, fmt.Errorf("%v : data type expect real slice, but get string", rule.Path) } + var ( + err error + res []any + ) if rule.SliceConfig.Mode == consts.DataSliceModelMarshal { // json序列化之后的 - var ( - err error - res []any - ) if err = serialize.JSON.UnmarshalWithNumber([]byte(inputStr), &res); nil != err { return nil, fmt.Errorf("%v : data type expect marshal slice, but can not convert", rule.Path) } @@ -257,15 +257,15 @@ func handleSliceString(inputStr string, rule *define.FieldRule) ([]any, error) { } if rule.SliceConfig.Mode == consts.DataSliceModelWithSplitChar { // 指定字符串切割 strArr := strings.Split(inputStr, rule.SliceConfig.SplitChar) - anyArr := make([]any, 0) + res = make([]any, 0) for _, item := range strArr { if !rule.SliceConfig.DisableIgnoreEmpty && len(item) == 0 { // 没禁用忽略空字符串 continue } - anyArr = append(anyArr, item) + res = append(res, item) } - return anyArr, nil + return res, nil } return nil, fmt.Errorf("%v : data type is slice, but rule mode [%v] is not supported", rule.Path, rule.SliceConfig.Mode) }