isEmptyValue returns true if the given value is empty. This is a copy of isEmptyValue from encoding/json to help determine when to write a field with `omitempty` set.
(v reflect.Value)
| 36 | // isEmptyValue from encoding/json to help determine when to write a field |
| 37 | // with `omitempty` set. |
| 38 | func isEmptyValue(v reflect.Value) bool { |
| 39 | switch v.Kind() { |
| 40 | case reflect.Array, reflect.Map, reflect.Slice, reflect.String: |
| 41 | return v.Len() == 0 |
| 42 | case reflect.Bool: |
| 43 | return !v.Bool() |
| 44 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 45 | return v.Int() == 0 |
| 46 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
| 47 | return v.Uint() == 0 |
| 48 | case reflect.Float32, reflect.Float64: |
| 49 | return v.Float() == 0 |
| 50 | case reflect.Interface, reflect.Pointer: |
| 51 | return v.IsNil() |
| 52 | } |
| 53 | return false |
| 54 | } |
| 55 | |
| 56 | // isNilValue returns true if the given value is nil. |
| 57 | func isNilValue(v any) bool { |
no test coverage detected
searching dependent graphs…