From 7cb23db8198970c76647c6492a280b4922ce9962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Wed, 15 Jan 2025 22:33:10 +0000 Subject: [PATCH] feat(reflectx): add is empty value --- reflectx/value.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 reflectx/value.go diff --git a/reflectx/value.go b/reflectx/value.go new file mode 100644 index 0000000..c0aae87 --- /dev/null +++ b/reflectx/value.go @@ -0,0 +1,17 @@ +package reflectx + +import "reflect" + +func IsEmptyValue(v reflect.Value) bool { + switch v.Kind() { + case reflect.Array, reflect.Map, reflect.Slice, reflect.String: + return v.Len() == 0 + case reflect.Bool, + reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, + reflect.Float32, reflect.Float64, + reflect.Interface, reflect.Pointer: + return v.IsZero() + } + return false +}