Documentation
¶
Overview ¶
Package reflectx holds pure reflection helpers extracted from the validate root package. It depends only on goutil and never imports the root package, keeping the dependency direction one-way (root -> internal/reflectx).
Index ¶
- Variables
- func ConvToBasicType(val any) (value any, err error)
- func ConvToBasicTypeRV(rv reflect.Value) (value any, err error)
- func ConvTypeByBaseKind(srcVal any, dstType reflect.Kind) (any, error)
- func GetVariadicKind(typ reflect.Type) reflect.Kind
- func IndirectValue(input any) any
- func IndirectValueRV(rv reflect.Value, orig any) any
- func IsNilObj(val any) bool
- func IsNilRV(rv reflect.Value) bool
- func RemoveValuePtr(t reflect.Value) reflect.Value
- func ValueCompare(srcVal, dstVal any, op string) (ok bool)
- type NilObject
Constants ¶
This section is empty.
Variables ¶
var ErrConvertFail = errors.New("convert value is failure")
ErrConvertFail error. Mirrors validate.ErrConvertFail; kept as a separate value because consumers only test err != nil, never the identity.
var NilRVal = reflect.ValueOf(nilObj)
NilRVal a reflect nil value (= reflect.ValueOf(NilObject{})).
Functions ¶
func ConvToBasicType ¶
ConvToBasicType convert custom type to generic basic int, string, unit. returns string, int64 or error
func ConvToBasicTypeRV ¶ added in v2.0.1
ConvToBasicTypeRV 同 ConvToBasicType,但直接吃 reflect.Value(复用调用方缓存, 免二次 reflect.ValueOf)。语义与 ConvToBasicType 字节级一致。
func ConvTypeByBaseKind ¶
ConvTypeByBaseKind convert value type by base kind
func IndirectValue ¶
IndirectValue dereferences a single pointer level of the input value.
func IndirectValueRV ¶ added in v2.0.1
IndirectValueRV is the reflect.Value flavour of IndirectValue: it dereferences a single pointer level of rv and returns the value as any. It mirrors IndirectValue's pointer / nil-pointer / non-pointer branches; orig is the boxed value rv was reflected from and is returned as-is for the non-pointer branch (no fresh boxing alloc — and identical to IndirectValue, which returns the original input unchanged for non-pointers).
NOTE: callers pass a carrier's RealV() here (already de-pointered one level), so this applies the SECOND indirection level — matching the reflect.Call path where the public IsBool receives RealV().Interface() and then does its own IndirectValue. RealV() substitutes NilRVal for a nil src (never an invalid Value), so a nil field surfaces as NilObject{} not nil — same as reflect.Call.
func IsNilRV ¶ added in v2.0.1
IsNilRV reports whether rv is the nil sentinel — an invalid Value or a NilObject — using a box-free Type comparison (no rv.Interface()). The carrier substitutes NilRVal for an untyped-nil src, so this detects "nil field" purely from the reflect.Value.
func RemoveValuePtr ¶
RemoveValuePtr removes value multiple pointer