reflectx

package
v0.0.0-...-d3b5644 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseKind

func BaseKind(a any) reflect.Kind

func FindFieldByTag

func FindFieldByTag(objValue reflect.Value, tagKey string, match func(tagVal string) bool) (reflect.Value, bool)

FindFieldByTag searches through the fields of a given struct value for a field that has a specific tag and whose tag value satisfies a given condition. It returns the reflect.Value of the matched field along with a boolean indicating whether a match was found.

Parameters:

v: The reflect.Value representing the struct to search.
tagKey: The key of the tag to look for.
match: A function that takes the tag value as a string and returns true if it satisfies the condition.

Returns:

A tuple containing the reflect.Value of the matched field and a boolean indicating if a match was found.

func GetByAccessor

func GetByAccessor[T any](accessor *Accessor, field string) (T, error)

func GetField

func GetField(objValue reflect.Value, field string) (any, error)

func Indirect

func Indirect(a any) any

Indirect returns the value, after dereferencing as many times as necessary to reach the base type (or nil). From html/template/content.go Copyright 2011 The Go Authors. All rights reserved.

func IndirectOrImplements

func IndirectOrImplements(v reflect.Value, ifaceTypes ...reflect.Type) reflect.Value

func IndirectType

func IndirectType(t reflect.Type) reflect.Type

func IndirectValue

func IndirectValue(v reflect.Value) reflect.Value

func IsEmptyValue

func IsEmptyValue(v reflect.Value) bool

func New

func New[T any]() T

func RangeArrayOrSlice

func RangeArrayOrSlice(obj any) ([]any, error)

func RangeFields

func RangeFields(objValue reflect.Value) (map[string]any, error)

func RangeMap

func RangeMap(obj any) ([]any, []any, error)

func SetByAccessor

func SetByAccessor[T any](accessor *Accessor, field string, val T) error

func SetField

func SetField(objValue reflect.Value, field string, newValue any) error

Types

type Accessor

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

func FieldAccessorOf

func FieldAccessorOf(objValue reflect.Value) (*Accessor, error)

func TagAccessorOf

func TagAccessorOf(objValue reflect.Value, key string) (*Accessor, error)

func (*Accessor) Get

func (accessor *Accessor) Get(field string) (any, error)

func (*Accessor) Set

func (accessor *Accessor) Set(field string, val any) error

Jump to

Keyboard shortcuts

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