From 2062e84b99b0004f8eb99bbe581181fe768f886b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 11 Jun 2023 21:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=8F=E4=B8=80=E9=A1=B9?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BAinterface=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.go | 15 +++++++++++++++ array_test.go | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/array.go b/array.go index 0a932bd..27e49a7 100644 --- a/array.go +++ b/array.go @@ -56,3 +56,18 @@ func (at *ArrayType) IsValid() bool { } return strings.HasPrefix(string(byteData), "[") && strings.HasSuffix(string(byteData), "]") } + +// ItemIsInterface 数组每一项是否为interface +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:20 2023/6/11 +func (at *ArrayType) ItemIsInterface() bool { + if !at.IsValid() { + return false + } + if _, ok := at.value.([]interface{}); ok { + return true + } + return false +} diff --git a/array_test.go b/array_test.go index d62d9e0..baddf77 100644 --- a/array_test.go +++ b/array_test.go @@ -13,6 +13,7 @@ import ( ) func TestArray(t *testing.T) { - val := []int64{1, 2, 3} + val := []interface{}{1, 2, 3} fmt.Println(Array(val).IsValid()) + fmt.Println(Array(val).ItemIsInterface()) }