From 65186fe23b6341f4e9fee7d12ee835a23bda2a8f 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, 11 Aug 2023 13:49:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/array.go b/array.go index 1b4678b..ac8156d 100644 --- a/array.go +++ b/array.go @@ -15,25 +15,25 @@ import ( "strings" ) -// Array 数组实例 +// ArrayType 数组实例 // // Author : go_developer@163.com<白茶清欢> // // Date : 21:03 2023/6/11 -func Array(value interface{}) *ArrayType { - at := &ArrayType{ +func ArrayType(value interface{}) *Array { + at := &Array{ value: value, } - at.Convert() + _, _ = at.Convert() return at } -// ArrayType ... +// Array ... // // Author : go_developer@163.com<白茶清欢> // // Date : 21:05 2023/6/11 -type ArrayType struct { +type Array struct { value interface{} convertResult []interface{} convertErr error @@ -46,7 +46,7 @@ type ArrayType struct { // Author : go_developer@163.com<白茶清欢> // // Date : 21:11 2023/6/11 -func (at *ArrayType) IsNil() bool { +func (at *Array) IsNil() bool { return at.value == nil } @@ -55,7 +55,7 @@ func (at *ArrayType) IsNil() bool { // Author : go_developer@163.com<白茶清欢> // // Date : 21:06 2023/6/11 -func (at *ArrayType) IsValid() bool { +func (at *Array) IsValid() bool { if at.IsNil() { return false } @@ -71,7 +71,7 @@ func (at *ArrayType) IsValid() bool { // Author : go_developer@163.com<白茶清欢> // // Date : 21:20 2023/6/11 -func (at *ArrayType) ItemIsInterface() bool { +func (at *Array) ItemIsInterface() bool { if !at.IsValid() { return false } @@ -86,7 +86,7 @@ func (at *ArrayType) ItemIsInterface() bool { // Author : go_developer@163.com<白茶清欢> // // Date : 17:59 2023/6/12 -func (at *ArrayType) Convert() ([]interface{}, error) { +func (at *Array) Convert() ([]interface{}, error) { if at.IsNil() { // 空指针 at.convertResult = make([]interface{}, 0) @@ -200,9 +200,7 @@ func (at *ArrayType) Convert() ([]interface{}, error) { at.isSimpleSlice = false at.itemType = reflect.Interface at.convertResult = make([]interface{}, len(val)) - for i := 0; i < len(val); i++ { - at.convertResult[i] = val[i] - } + copy(at.convertResult, val) } return at.convertResult, nil } @@ -212,7 +210,7 @@ func (at *ArrayType) Convert() ([]interface{}, error) { // Author : go_developer@163.com<白茶清欢> // // Date : 18:07 2023/6/26 -func (at *ArrayType) ConvertIgnoreError() []interface{} { +func (at *Array) ConvertIgnoreError() []interface{} { res, _ := at.Convert() return res } @@ -222,7 +220,7 @@ func (at *ArrayType) ConvertIgnoreError() []interface{} { // Author : go_developer@163.com<白茶清欢> // // Date : 17:43 2023/6/12 -func (at *ArrayType) Unique() []interface{} { +func (at *Array) Unique() []interface{} { result := make([]interface{}, 0) if at.isSimpleSlice { // 简单数据类型 @@ -245,7 +243,7 @@ func (at *ArrayType) Unique() []interface{} { // Author : go_developer@163.com<白茶清欢> // // Date : 16:28 2023/7/31 -func (at *ArrayType) In(input interface{}) int { +func (at *Array) In(input interface{}) int { for idx := 0; idx < len(at.convertResult); idx++ { if nil == input { if nil != at.convertResult[idx] {