From 1ca4b993fb2479936385533059d5e0cad4c11134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 26 Jun 2023 18:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84convert=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/array.go b/array.go index 1e2c966..99b0bf5 100644 --- a/array.go +++ b/array.go @@ -86,16 +86,16 @@ func (at *ArrayType) ItemIsInterface() bool { // Author : go_developer@163.com<白茶清欢> // // Date : 17:59 2023/6/12 -func (at *ArrayType) Convert() { +func (at *ArrayType) Convert() ([]interface{}, error) { if at.IsNil() { // 空指针 at.convertResult = make([]interface{}, 0) - return + return at.convertResult, nil } if !at.IsValid() { // 无效slice at.convertErr = errors.New("input slice is invalid") - return + return nil, at.convertErr } switch val := at.value.(type) { case []int8: @@ -204,6 +204,17 @@ func (at *ArrayType) Convert() { at.convertResult[i] = val[i] } } + return at.convertResult, nil +} + +// ConvertIgnoreError 类型转换并忽略异常 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 18:07 2023/6/26 +func (at *ArrayType) ConvertIgnoreError() []interface{} { + res, _ := at.Convert() + return res } // Unique 对数据结果进行去重