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()) +}