refl

package
v0.61.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyPointerSlice

func CopyPointerSlice(ptrA any, ptrB any)

func CreatePointerToSliceOfTypeAndSize

func CreatePointerToSliceOfTypeAndSize(value any, size int) any

func Flatten added in v0.54.2

func Flatten(elements ...any) []any

Flatten takes a variadic list of elements and flattens any slices or arrays found at the top level into a single []any slice. Non-slice elements are preserved as-is in the output. Pointers to slices/arrays are dereferenced before flattening.

Note: This function only performs one level of flattening. Nested slices within slices are not recursively flattened.

Examples:

Flatten(1, 2, 3) // returns []any{1, 2, 3}
Flatten([]int{1, 2}, 3) // returns []any{1, 2, 3}
Flatten([]int{1, 2}, []string{"a", "b"}) // returns []any{1, 2, "a", "b"}
Flatten(1, []int{2, 3}, 4, []string{"a"}) // returns []any{1, 2, 3, 4, "a"}
Flatten([3]int{1, 2, 3}) // returns []any{1, 2, 3} (arrays work too)
Flatten([]any{1, []int{2, 3}}) // returns []any{1, []int{2, 3}} (no recursive flattening)
slice := []int{1, 2}; Flatten(&slice) // returns []any{1, 2} (pointers are dereferenced)

func GetTagNames added in v0.51.2

func GetTagNames(v any) []string

GetTagNames returns a sorted list of distinct struct tag keys present on the fields of the given value. Works with structs, pointers to structs, and slices of structs. Returns an empty slice for nil or non-structs.

func GetTags added in v0.21.5

func GetTags(v any, tagName string) []string

GetTags reads the values of tags with the name tagName. Tag values get extracted until the first comma. Best suited to read json and db tags.

func GetTypedValue

func GetTypedValue(value any) reflect.Value

func InitializeMapsAndSlices

func InitializeMapsAndSlices(value any)

func InterfaceToInterfaceSlice

func InterfaceToInterfaceSlice(in any) ([]any, error)

func InterfaceToMapInterfaceInterface

func InterfaceToMapInterfaceInterface(m any) (map[any]any, error)

func IsPointerToMap

func IsPointerToMap(value any) bool

func IsPointerToSlice

func IsPointerToSlice(value any) bool

func IsPointerToStruct

func IsPointerToStruct(value any) bool

func IsSlice

func IsSlice(value any) bool

func IsStructOrPointerToStruct

func IsStructOrPointerToStruct(value any) bool

func ResolveBaseType

func ResolveBaseType(value any) reflect.Type

func ResolveBaseTypeAndValue

func ResolveBaseTypeAndValue(value any) (reflect.Type, reflect.Value)

func ResolveValueTo

func ResolveValueTo(value any, kind reflect.Kind) (reflect.Type, reflect.Value)

func SliceInterfaceIterator

func SliceInterfaceIterator(slice any) *sliceIterator

func Unbox added in v0.36.1

func Unbox(val any) any

func ValueToPointerValue added in v0.26.0

func ValueToPointerValue(val any) any

Types

type Map

type Map struct {
	// contains filtered or unexported fields
}

func MapOf

func MapOf(m any) (*Map, error)

func (*Map) NewElement

func (m *Map) NewElement() any

func (*Map) Set

func (m *Map) Set(key any, value any) error

type Slice

type Slice struct {
	// contains filtered or unexported fields
}

func SliceOf

func SliceOf(slice any) (*Slice, error)

func (*Slice) Append

func (s *Slice) Append(elem any) error

func (*Slice) NewElement

func (s *Slice) NewElement() any

Jump to

Keyboard shortcuts

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