From ef80c6cb79d12be3a71d57f913dc4cc02cb269a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 24 Sep 2024 14:34:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DanyType=20IsNil=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- any.go | 10 +++++++++- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/any.go b/any.go index 5454fa7..adf3e2b 100644 --- a/any.go +++ b/any.go @@ -46,7 +46,15 @@ func (at *AnyType) IsNil() bool { if at.data == nil { return true } - return reflect.ValueOf(at.data).IsNil() + reflectValue := reflect.ValueOf(at.data) + switch reflectValue.Kind() { + case reflect.Chan, reflect.Func, reflect.Map, + reflect.Pointer, reflect.UnsafePointer, + reflect.Interface, reflect.Slice: + return reflectValue.IsNil() + default: + return false + } } // Type 获取类型 diff --git a/go.mod b/go.mod index e21ee1b..7b407b4 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.21.4 require ( - git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4 + git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5 git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 git.zhangdeman.cn/zhangdeman/op_type v0.0.0-20240122104027-4928421213c0 git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20240618035451-8d48a6bd39dd diff --git a/go.sum b/go.sum index edc9cc6..4044fef 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7 h1:QR8vMX git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240612081722-31c64d4d4ce7/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4 h1:mibnyzYbZullK0aTHVASHl3UeoVr8IgytQZsuyv+yEM= git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240726024939-e424db29c5c4/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5 h1:pmIHln0gWW+5xAB762h3WDsRkZuYLUDndvJDsGMKoOY= +git.zhangdeman.cn/zhangdeman/consts v0.0.0-20240823041145-d4df71cf37e5/go.mod h1:IXXaZkb7vGzGnGM5RRWrASAuwrVSNxuoe0DmeXx5g6k= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4 h1:93JYY8JLbFcrlq37q/uKyxs2r2e3modsjvfSbnZQ/UI= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240130062251-a87a97b0e8d4/go.mod h1:SrtvrQRdzt+8KfYzvosH++gWxo2ShPTzR1m3VQ6uX7U= git.zhangdeman.cn/zhangdeman/easymap v0.0.0-20240311030808-e2a2e6a3c211 h1:I/wOsRpCSRkU9vo1u703slQsmK0wnNeZzsWQOGtIAG0=