Documentation
¶
Overview ¶
Package reflectx GENERATED BY code_error DO NOT EDIT
Index ¶
- Variables
- func CanCast[T any](v any) bool
- func CanElem(t reflect.Type) bool
- func CanNilValue(v any) bool
- func Deref(t reflect.Type) reflect.Type
- func DerefPointer(t reflect.Type) reflect.Type
- func Indirect(v any) reflect.Value
- func IndirectNew(v any) reflect.Value
- func IsBytes(v any) bool
- func IsFloat(v any) bool
- func IsInteger(v any) bool
- func IsNumeric(v any) bool
- func IsZero(v any) bool
- func KindOf(v any) reflect.Kind
- func MustType[T any](v any) T
- func New(t reflect.Type) reflect.Value
- func NewElem(t reflect.Type) reflect.Value
- func TypeOf(v any) reflect.Type
- func Typename(rt reflect.Type) string
- type Ecode
- type Flag
- type Option
- type Tag
- type ZeroChecker
Constants ¶
This section is empty.
Variables ¶
var TypeZeroChecker = reflect.TypeFor[ZeroChecker]()
Functions ¶
func CanElem ¶ added in v0.0.24
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
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 Indirect ¶
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 ¶
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 IsNumeric ¶
IsNumeric reports whether the value v is of a numeric type. This includes all integer, unsigned integer, float, and complex number types.
func IsZero ¶
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
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.
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 )
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,
}
}
type Tag ¶ added in v0.1.1
func ParseTag ¶ added in v0.1.1
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.
type ZeroChecker ¶ added in v0.1.0
type ZeroChecker interface {
IsZero() bool
}