isEmptyValue gets whether the specified reflect.Value is considered empty or not.
(objValue reflect.Value)
| 758 | |
| 759 | // isEmptyValue gets whether the specified reflect.Value is considered empty or not. |
| 760 | func isEmptyValue(objValue reflect.Value) bool { |
| 761 | if objValue.IsZero() { |
| 762 | return true |
| 763 | } |
| 764 | // Special cases of non-zero values that we consider empty |
| 765 | switch objValue.Kind() { |
| 766 | // collection types are empty when they have no element |
| 767 | // Note: array types are empty when they match their zero-initialized state. |
| 768 | case reflect.Chan, reflect.Map, reflect.Slice: |
| 769 | return objValue.Len() == 0 |
| 770 | // non-nil pointers are empty if the value they point to is empty |
| 771 | case reflect.Ptr: |
| 772 | return isEmptyValue(objValue.Elem()) |
| 773 | } |
| 774 | return false |
| 775 | } |
| 776 | |
| 777 | // Empty asserts that the given value is "empty". |
| 778 | // |