reflectx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 9 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidValue = reflect.Value{}
	InvalidType  = reflect.TypeOf(nil)
)
View Source
var TypeZeroChecker = reflect.TypeFor[ZeroChecker]()

Functions

func AssertType added in v0.0.34

func AssertType[T any](v any) (T, bool)

func CanCast added in v0.0.34

func CanCast[T any](v any) bool

func CanElem added in v0.0.24

func CanElem(k reflect.Kind) bool

func Clone added in v0.0.26

func Clone[T any](src T) (dst T)

func DeepCopy added in v0.0.26

func DeepCopy(v, x reflect.Value)

func Deref

func Deref(t reflect.Type) reflect.Type

Deref returns the basic type of t

func HackField added in v0.0.32

func HackField(v any, i int) reflect.Value

func HackFieldByName added in v0.0.32

func HackFieldByName(v any, name string) reflect.Value

func Indirect

func Indirect(v any) reflect.Value

Indirect deref all level pointer references

func IndirectNew

func IndirectNew(v any) reflect.Value

IndirectNew returns the indirect value of v this function is safe and WILL NOT trigger panic. if the input is invalid, InvalidValue returns. validation of return is recommended.

func IsBytes

func IsBytes(v any) bool

func IsFloat

func IsFloat(v any) bool

func IsInteger

func IsInteger(v any) bool

func IsNumeric

func IsNumeric(v any) bool

func IsZero

func IsZero(v any) bool

IsZero checks whether the given value is zero or its underlying value is zero

If the value implements the ZeroChecker interface, IsZero will use its IsZero method to determine zero-ness. Special handling is provided for slices, maps, strings, and channels, which are considered zero if their length is zero.

func MustAssertType added in v0.0.34

func MustAssertType[T any](v any) T

func New

func New(t reflect.Type) reflect.Value

New a `reflect.Value` with reflect.Type not like reflect.New, but new all level pointer ref

func NewElem

func NewElem(t reflect.Type) reflect.Value

NewElem new the indirect type of t

func Typename

func Typename(rt reflect.Type) string

Typename returns the full type name of rt

Types

type Flag added in v0.1.0

type Flag struct {
	Name    string
	Options [][2]string
}

Flag represents a single tag value with optional key-value options. For example, the tag `name:"field,opt1,opt2=v2"` will be parsed into: {Name: "field", Options: [][2]string{{"opt1": ""}, {"opt2": "v2"}}}

func (Flag) TagValue added in v0.1.0

func (f Flag) TagValue() string

type Flags added in v0.1.0

type Flags map[string]*Flag

func ParseFlags added in v0.1.0

func ParseFlags(tag reflect.StructTag) Flags

ParseFlags parses struct tag annotations into a structured Flags map. It supports tag formats like: `key:"value,opt1,opt2=v2"`. Each key-value pair in the tag is processed into a Flag with Value and Options. Conflicting tags (i.e., duplicate keys) will be detected and removed. The function also handles quoted values and options with or without values.

func (Flags) Get added in v0.1.0

func (fs Flags) Get(key string) *Flag

type ZeroChecker added in v0.1.0

type ZeroChecker interface {
	IsZero() bool
}

Jump to

Keyboard shortcuts

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