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) {
return stringifyValue(value)
})
StringConverter converts values to strings.
Nil interface and pointer values are rendered as `<nil>`. For non-nil values, it prefers fmt.Stringer, then encoding.TextMarshaler. If neither applies, scalar values use the same formatting as flattening, structs use `%+v`, arrays and slices stringify each item recursively, maps stringify each key and value recursively, pointers use `<pointer> -> <converted pointed value>`, and everything else falls back to fmt.Sprint. Errors returned by encoding.TextMarshaler.MarshalText are 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.