func ZeroOrNil()

in pkg/utils/utils.go [23:50]


func ZeroOrNil(obj interface{}) bool {
	if obj == nil {
		return true
	}

	// IsValid returns false if value is the zero Value
	value := reflect.ValueOf(obj)
	if !value.IsValid() {
		return true
	}

	// For array, slice, map check if the length is 0
	switch value.Kind() {
	case reflect.Slice, reflect.Array, reflect.Map:
		return value.Len() == 0
	}

	if !value.Type().Comparable() {
		return false
	}

	// Create the zero valued the type and compare
	zero := reflect.Zero(reflect.TypeOf(obj))
	if obj == zero.Interface() {
		return true
	}
	return false
}