reflectx

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 11 Imported by: 8

Documentation

Overview

Package reflectx GENERATED BY code_error DO NOT EDIT

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 CanCast added in v0.0.34

func CanCast[T any](v any) bool

func CanElem added in v0.0.24

func CanElem(t reflect.Type) bool

CanElem reports whether the given value's kind supports calling .Elem().

It returns true if the underlying kind is one of: Array, Chan, Map, Pointer, or Slice. Otherwise, it returns false.

func CanNilValue added in v0.1.1

func CanNilValue(v any) bool

CanNilValue reports whether the given value can be nil.

It returns true for kinds that can have nil values, such as channels, functions, interfaces, maps, pointers, slices, and unsafe pointers. Otherwise, it returns false. If the input has no valid type information, it returns false.

func Deref

func Deref(t reflect.Type) reflect.Type

Deref returns the basic type of t

func DerefPointer added in v0.2.1

func DerefPointer(t reflect.Type) reflect.Type

func Indirect

func Indirect(v any) reflect.Value

Indirect recursively dereferences a value until it reaches a concrete value that is either not a pointer or interface, or is a named type.

It accepts either a `reflect.Value` or any Go value. If the input is invalid (e.g., nil), it returns reflectx.InvalidValue.

This function differs from reflect.Indirect in that it recursively dereferences anonymous (unnamed) pointer and interface types until a named type or base value is encountered. This is useful when working with nested values such as interface{} holding a pointer to a pointer, etc.

It safely handles nil pointers and interfaces by returning InvalidValue instead of panicking.

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

IsNumeric reports whether the value v is of a numeric type. This includes all integer, unsigned integer, float, and complex number types.

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 KindOf added in v0.1.1

func KindOf(v any) reflect.Kind

KindOf returns the kind of the given value.

It accepts inputs of type reflect.Value, reflect.Type, or any Go value, and returns the underlying kind accordingly.

func MustType added in v0.1.1

func MustType[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 TypeOf added in v0.2.0

func TypeOf(v any) reflect.Type

func Typename

func Typename(rt reflect.Type) string

Typename returns the full type name of rt

Types

type Ecode added in v0.2.0

type Ecode int8

Ecode defines error codes for tag parsing +genx:code_error @def PARSING_TAG

const (
	ECODE_UNDEFINED                Ecode = iota
	ECODE__INVALID_FLAG_KEY              // invalid flag key
	ECODE__INVALID_FLAG_VALUE            // invalid flag value
	ECODE__INVALID_FLAG_NAME             // invalid flag flag name
	ECODE__INVALID_OPTION_KEY            // invalid option key
	ECODE__INVALID_OPTION_VALUE          // invalid option value
	ECODE__INVALID_OPTION_UNQUOTED       // invalid option unquoted
)

func (Ecode) Message added in v0.2.0

func (e Ecode) Message() string

type Flag added in v0.1.0

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

Flag parsed tag element eg: `db:"f_column,default='0',width=10,precision=4,primary"` the result is

{
  key:     "db",
  value:   "f_column,default='0',width=12,precision=4,primary",
  name:    "f_column"
  options: {
    "default":   '0',
    "width":     12,
    "precision": 4,
    "primary":   nil,
  }
}

func (*Flag) HasOption added in v0.2.0

func (f *Flag) HasOption(key string) bool

func (*Flag) Key added in v0.1.1

func (f *Flag) Key() string

func (*Flag) Name added in v0.1.0

func (f *Flag) Name() string

func (*Flag) Option added in v0.1.1

func (f *Flag) Option(key string) *Option

func (*Flag) OptionLen added in v0.1.1

func (f *Flag) OptionLen() int

func (*Flag) Options added in v0.1.0

func (f *Flag) Options() iter.Seq[*Option]

func (*Flag) String added in v0.1.1

func (f *Flag) String() string

func (*Flag) Value added in v0.1.1

func (f *Flag) Value() string

type Option added in v0.1.1

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

func NewOption added in v0.1.1

func NewOption(key string, val string, offset int) *Option

func (*Option) IsZero added in v0.1.1

func (o *Option) IsZero() bool

func (*Option) Key added in v0.1.1

func (o *Option) Key() string

func (*Option) Quoted added in v0.2.0

func (o *Option) Quoted() string

func (*Option) String added in v0.1.1

func (o *Option) String() string

func (*Option) Unquoted added in v0.2.0

func (o *Option) Unquoted() string

func (*Option) Value added in v0.1.1

func (o *Option) Value() string

Value returns literal text of option. eg: `db:"f_id,auto_inc,default='100'` Value() returns '100', Unquoted returns 100

type Tag added in v0.1.1

type Tag map[string]*Flag

func ParseTag added in v0.1.1

func ParseTag(tag reflect.StructTag) Tag

ParseTag parses a struct tag into a map of flag keys and values. Each value is further parsed into a flag name and its options. Control characters are allowed only in option values. Flag keys, flag names, and option names may contain only letters, digits, and underscores. Other characters in option values must be wrapped in single quotes.

func (Tag) Get added in v0.1.1

func (t Tag) Get(key string) *Flag

type ZeroChecker added in v0.1.0

type ZeroChecker interface {
	IsZero() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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