Skip to content

Commit

Permalink
Update isBlank checker
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jan 25, 2017
1 parent 7fb9b62 commit 89f6d74
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ func fileWithLineNum() string {
}

func isBlank(value reflect.Value) bool {
switch value.Kind() {
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
return value.Len() == 0
case reflect.Bool:
return !value.Bool()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return value.Int() == 0
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return value.Uint() == 0
case reflect.Float32, reflect.Float64:
return value.Float() == 0
case reflect.Interface, reflect.Ptr:
return value.IsNil()
}

return reflect.DeepEqual(value.Interface(), reflect.Zero(value.Type()).Interface())
}

Expand Down

0 comments on commit 89f6d74

Please sign in to comment.