From 9db9e2d4292051e65c45d35583f4a2b522d92600 Mon Sep 17 00:00:00 2001 From: soranoba Date: Fri, 15 Jan 2021 14:42:51 +0900 Subject: [PATCH] isEmpty can returns true, if an argument is any struct other than time.Time --- util.go | 6 +----- util_test.go | 9 ++++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/util.go b/util.go index b15fd9a..faa0e58 100644 --- a/util.go +++ b/util.go @@ -9,7 +9,6 @@ import ( "errors" "fmt" "reflect" - "time" ) var ( @@ -117,10 +116,7 @@ func IsEmpty(value interface{}) bool { } return IsEmpty(v.Elem().Interface()) case reflect.Struct: - v, ok := value.(time.Time) - if ok && v.IsZero() { - return true - } + return v.IsZero() } return false diff --git a/util_test.go b/util_test.go index fa4a047..f7bde4b 100644 --- a/util_test.go +++ b/util_test.go @@ -195,7 +195,8 @@ func TestIsEmpty(t *testing.T) { var s1 string var s2 = "a" var s3 *string - s4 := struct{}{} + s4 := struct{A string}{} + s5 := struct{A string}{A: "a"} time1 := time.Now() var time2 time.Time tests := []struct { @@ -251,8 +252,10 @@ func TestIsEmpty(t *testing.T) { {"t8.2", &s2, false}, {"t8.3", s3, true}, // struct - {"t9.1", s4, false}, - {"t9.2", &s4, false}, + {"t9.1", s4, true}, + {"t9.2", &s4, true}, + {"t9.3", s5, false}, + {"t9.4", &s5, false}, // time.Time {"t10.1", time1, false}, {"t10.2", &time1, false},