isEmptyValue checks if a value should be considered empty for the purposes of omitting fields with the "omitempty" option.
(v reflect.Value)
| 314 | // isEmptyValue checks if a value should be considered empty for the purposes |
| 315 | // of omitting fields with the "omitempty" option. |
| 316 | func isEmptyValue(v reflect.Value) bool { |
| 317 | switch v.Kind() { |
| 318 | case reflect.Array, reflect.Map, reflect.Slice, reflect.String: |
| 319 | return v.Len() == 0 |
| 320 | case reflect.Bool: |
| 321 | return !v.Bool() |
| 322 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 323 | return v.Int() == 0 |
| 324 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
| 325 | return v.Uint() == 0 |
| 326 | case reflect.Float32, reflect.Float64: |
| 327 | return v.Float() == 0 |
| 328 | case reflect.Interface, reflect.Ptr: |
| 329 | return v.IsNil() |
| 330 | } |
| 331 | |
| 332 | type zeroable interface { |
| 333 | IsZero() bool |
| 334 | } |
| 335 | |
| 336 | if z, ok := v.Interface().(zeroable); ok { |
| 337 | return z.IsZero() |
| 338 | } |
| 339 | |
| 340 | return false |
| 341 | } |
| 342 | |
| 343 | // tagOptions is the string following a comma in a struct field's "url" tag, or |
| 344 | // the empty string. It does not include the leading comma. |
searching dependent graphs…