Skip to content

Commit

Permalink
slightly cleanup nil handling
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Szczygieł <1153719+mszczygiel@users.noreply.github.com>
  • Loading branch information
mszczygiel committed Mar 27, 2023
1 parent 370a73b commit d2ff6fd
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func IsZero(data interface{}) bool {
v := reflect.ValueOf(data)
// check for nil data
switch v.Kind() {
case reflect.Interface, reflect.Ptr:
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
if v.IsNil() {
return true
}
Expand All @@ -367,14 +367,13 @@ func IsZero(data interface{}) bool {
return v.Uint() == 0
case reflect.Float32, reflect.Float64:
return v.Float() == 0
case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
return v.IsNil()
case reflect.Struct, reflect.Array:
return reflect.DeepEqual(data, reflect.Zero(v.Type()).Interface())
case reflect.Invalid:
return true
default:
return false
}
return false
}

// AddInitialisms add additional initialisms
Expand Down

0 comments on commit d2ff6fd

Please sign in to comment.