value

package
v1.170.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty(value any) bool

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

func IsNilInterface(i any) bool

IsNilInterface checks whether an interface value is nil even when it has been passed around as `any`.

func IsNotEmpty added in v1.161.0

func IsNotEmpty(value any) bool

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

type IValueConverter interface {
	ConvertValue(ctx context.Context, value any) (any, error)
}

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

type ValueConverterFunc func(ctx context.Context, value any) (any, error)

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

func (f ValueConverterFunc) ConvertValue(ctx context.Context, value any) (any, error)

ConvertValue applies f to value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL