reflection

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 6 Imported by: 0

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

func AssignFromString(value reflect.Value, stringEncodedValue string) error

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

func Dereference(value reflect.Value) reflect.Value

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

func DereferenceType(t reflect.Type) reflect.Type

DereferenceType returns the base type after dereferencing all pointer indirections.

func IsNil

func IsNil(value reflect.Value) bool

IsNil returns true if the value is nil.

func Nillable

func Nillable(kind reflect.Kind) bool

Nillable returns true if the kind supports the IsNil function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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