MCPcopy
hub / github.com/duke-git/lancet / IsZeroValue

Function IsZeroValue

validator/validator.go:449–479  ·  view source on GitHub ↗

IsZeroValue checks if value is a zero value. Play: https://go.dev/play/p/UMrwaDCi_t4

(value any)

Source from the content-addressed store, hash-verified

447// IsZeroValue checks if value is a zero value.
448// Play: https://go.dev/play/p/UMrwaDCi_t4
449func IsZeroValue(value any) bool {
450 if value == nil {
451 return true
452 }
453
454 rv := reflect.ValueOf(value)
455 if rv.Kind() == reflect.Ptr {
456 rv = rv.Elem()
457 }
458
459 if !rv.IsValid() {
460 return true
461 }
462
463 switch rv.Kind() {
464 case reflect.String:
465 return rv.Len() == 0
466 case reflect.Bool:
467 return !rv.Bool()
468 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
469 return rv.Int() == 0
470 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
471 return rv.Uint() == 0
472 case reflect.Float32, reflect.Float64:
473 return rv.Float() == 0
474 case reflect.Ptr, reflect.Chan, reflect.Func, reflect.Interface, reflect.Slice, reflect.Map:
475 return rv.IsNil()
476 }
477
478 return reflect.DeepEqual(rv.Interface(), reflect.Zero(rv.Type()).Interface())
479}
480
481// IsGBK check if data encoding is gbk
482// Note: this function is implemented by whether double bytes fall within the encoding range of gbk,

Callers 2

TestIsZeroValueFunction · 0.85
ExampleIsZeroValueFunction · 0.85

Calls 4

KindMethod · 0.80
ValueOfMethod · 0.45
LenMethod · 0.45
IsNilMethod · 0.45

Tested by 2

TestIsZeroValueFunction · 0.68
ExampleIsZeroValueFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…