Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEmpty ¶
IsEmpty checks whether a value is empty i.e. "", nil, 0, [], {}, false, etc. For Strings, a string is considered empty if it is "" or if it only contains whitespaces
func IsNilInterface ¶ added in v1.158.0
IsNilInterface checks whether an interface value is nil even when it has been passed around as `any`.
func IsNotEmpty ¶ added in v1.161.0
IsNotEmpty checks whether a value is not empty. See IsEmpty for more details about what is considered empty.
Types ¶
type IValueConverter ¶ added in v1.170.0
IValueConverter converts a value before it is consumed by a caller.
Implementations may use ctx to observe cancellation, access request-scoped metadata, or carry other conversion-time state. The returned value replaces the original input. A non-nil error reports that conversion failed and should usually stop the caller's processing.
var IdentityConverter IValueConverter = ValueConverterFunc(func(_ context.Context, value any) (any, error) { return value, nil })
IdentityConverter returns values unchanged.
It ignores ctx and always succeeds.
var StringConverter IValueConverter = ValueConverterFunc(func(_ context.Context, value any) (any, error) { if stringer, ok := value.(fmt.Stringer); ok && !isNilMethodReceiver(value) { return stringer.String(), nil } if textMarshaler, ok := value.(encoding.TextMarshaler); ok && !isNilMethodReceiver(value) { text, err := textMarshaler.MarshalText() if err != nil { return nil, err } return string(text), nil } if isNilMethodReceiver(value) { return fmt.Sprint(nil), nil } return fmt.Sprint(value), nil })
StringConverter converts values to strings.
It prefers fmt.Stringer when available, then encoding.TextMarshaler, and otherwise falls back to fmt.Sprint.
Nil pointer and interface receivers do not have custom methods invoked; they are rendered as `<nil>` instead. When encoding.TextMarshaler returns an error, that error is propagated to the caller.
type ValueConverterFunc ¶ added in v1.170.0
ValueConverterFunc adapts a function into IValueConverter.
A nil function behaves like IdentityConverter: it returns the input value unchanged and reports no error.
func (ValueConverterFunc) ConvertValue ¶ added in v1.170.0
ConvertValue applies f to value.