Documentation
¶
Overview ¶
Package reflection provides utilities for working with Go's reflect package.
The standard library's reflect package can be cumbersome for certain common operations. This package addresses two frequent pain points: safely checking whether a value is nil and dereferencing pointers or interfaces to access underlying values and types.
Use this package when you need to inspect values at runtime and want to avoid the panics that can occur when calling IsNil on reflect.Value kinds that do not support it, or when you need to traverse through layers of pointers and interfaces to reach the concrete value or type.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignFromString ¶
AssignFromString parses a string-encoded value and sets it into the provided reflect.Value. The value must be settable (typically obtained via reflect.ValueOf(&x).Elem() or a struct field). The function handles various data types including basic types (string, int, bool, float, complex), complex types (structs, slices, arrays, maps) and types implementing the encoding.TextUnmarshaler interface. The conversion from string to the appropriate type is performed based on the underlying type. JSON format is expected for complex types like maps, slices, arrays, and structs. If the provided value is a pointer, the function allocates a new value and assigns it. An error is returned for unsupported types such as Chan, Func, Interface, UnsafePointer, and Uintptr.
func Dereference ¶
Dereference returns the value after dereferencing pointers and interfaces. In the case of types that can be nil but aren't pointers, such as maps or slices, it does nothing.
func DereferenceType ¶
DereferenceType returns the base type after dereferencing all pointer indirections.
Types ¶
This section is empty.