Update isBlank checker

This commit is contained in:
Jinzhu 2017-01-25 17:42:15 +08:00
parent 7fb9b62c17
commit 89f6d74b5e
1 changed files with 15 additions and 0 deletions

View File

@ -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())
}