Documentation
¶
Index ¶
- Variables
- func CanCast[T any](v any) bool
- func CanElemType(v any) bool
- func CanNilValue(v any) bool
- func Deref(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 Typename(rt reflect.Type) string
- type Flag
- type Option
- type Tag
- type ZeroChecker
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidFlagKey = errors.New("invalid flag key") ErrInvalidFlagValue = errors.New("invalid flag value") ErrInvalidFlagName = errors.New("invalid flag name") ErrInvalidOptionKey = errors.New("invalid option key") ErrInvalidOptionValue = errors.New("invalid option value") ErrInvalidOptionUnquoted = errors.New("invalid option unquoted") )
var TypeZeroChecker = reflect.TypeFor[ZeroChecker]()
Functions ¶
func CanElemType ¶ added in v0.1.1
CanElemType reports whether the given value's kind supports calling .Elem().
It accepts a value of any type, including `reflect.Kind`, `reflect.Type`, reflect.Value, or other Go values. It returns true if the underlying kind is one of: Array, Chan, Interface, Map, Pointer, or Slice. Otherwise, it returns false. Check if v CanElemType before use reflect.Type.Elem() is recommended to avoid panic
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 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) QuotedValue ¶ added in v0.1.1
func (*Flag) UnquotedValue ¶ added in v0.1.1
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
}