From bd989696a1ff63e3a31d77427d1208d694f087df 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:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E6=95=88=E6=95=B0=E7=BB=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ array_test.go | 18 ++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 array.go create mode 100644 array_test.go diff --git a/array.go b/array.go new file mode 100644 index 0000000..0a932bd --- /dev/null +++ b/array.go @@ -0,0 +1,58 @@ +// Package wrapper ... +// +// Description : wrapper ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-06-11 21:02 +package wrapper + +import ( + "encoding/json" + "strings" +) + +// Array 数组实例 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:03 2023/6/11 +func Array(value interface{}) *ArrayType { + return &ArrayType{ + value: value, + } +} + +// ArrayType ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:05 2023/6/11 +type ArrayType struct { + value interface{} +} + +// IsNil 输入是否为nil +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:11 2023/6/11 +func (at *ArrayType) IsNil() bool { + return at.value == nil +} + +// IsValid 检测是否为数组类型 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 21:06 2023/6/11 +func (at *ArrayType) IsValid() bool { + if at.IsNil() { + return false + } + byteData, err := json.Marshal(at.value) + if nil != err { + return false + } + return strings.HasPrefix(string(byteData), "[") && strings.HasSuffix(string(byteData), "]") +} diff --git a/array_test.go b/array_test.go new file mode 100644 index 0000000..d62d9e0 --- /dev/null +++ b/array_test.go @@ -0,0 +1,18 @@ +// Package wrapper ... +// +// Description : wrapper ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2023-06-11 21:12 +package wrapper + +import ( + "fmt" + "testing" +) + +func TestArray(t *testing.T) { + val := []int64{1, 2, 3} + fmt.Println(Array(val).IsValid()) +}