Documentation ¶
Overview ¶
Package reflects Provide extends reflect util functions.
Index ¶
- Constants
- func BaseTypeVal(v reflect.Value) (value any, err error)
- func Elem(v reflect.Value) reflect.Value
- func FlatMap(rv reflect.Value, fn FlatFunc)
- func HasChild(v reflect.Value) bool
- func Indirect(v reflect.Value) reflect.Value
- func IsEmpty(v reflect.Value) bool
- func IsEmptyValue(v reflect.Value) bool
- func IsEqual(src, dst any) bool
- func IsFunc(val any) bool
- func IsNil(v reflect.Value) bool
- func Len(v reflect.Value) int
- func SetValue(rv reflect.Value, val any) error
- func SliceSubKind(typ reflect.Type) reflect.Kind
- func String(rv reflect.Value) string
- func ToString(rv reflect.Value) (str string, err error)
- func ValToString(rv reflect.Value, defaultAsErr bool) (str string, err error)
- func ValueByKind(val any, kind reflect.Kind) (rv reflect.Value, err error)
- func ValueByType(val any, typ reflect.Type) (rv reflect.Value, err error)
- type BKind
- type FlatFunc
- type Type
- type Value
Constants ¶
const ( // Int for all intX types Int = BKind(reflect.Int) // Uint for all uintX types Uint = BKind(reflect.Uint) // Float for all floatX types Float = BKind(reflect.Float32) // Array for array,slice types Array = BKind(reflect.Array) // Complex for all complexX types Complex = BKind(reflect.Complex64) )
base kinds
Variables ¶
This section is empty.
Functions ¶
func BaseTypeVal ¶ added in v0.5.10
BaseTypeVal convert custom type or intX,uintX,floatX to generic base type.
intX/unitX => int64 floatX => float64 string => string
returns int64,string,float or error
func FlatMap ¶ added in v0.5.12
FlatMap process tree map to flat key-value map.
Examples:
{"top": {"sub": "value", "sub2": "value2"} } -> {"top.sub": "value", "top.sub2": "value2" }
func Indirect ¶ added in v0.5.12
Indirect like reflect.Indirect(), but can also indirect reflect.Interface
func IsEmptyValue ¶ added in v0.5.8
IsEmptyValue reflect value check. Difference the IsEmpty(), if value is ptr, will check real elem.
From src/pkg/encoding/json/encode.go.
func IsEqual ¶ added in v0.5.6
IsEqual determines if two objects are considered equal.
TIP: cannot compare function type
func SliceSubKind ¶ added in v0.5.8
SliceSubKind get sub-elem kind of the array, slice, variadic-var.
Usage:
SliceSubKind(reflect.TypeOf([]string{"abc"})) // reflect.String
func ValToString ¶ added in v0.5.12
ValToString convert handle
func ValueByKind ¶ added in v0.5.10
ValueByKind create reflect.Value by give reflect.Kind
TIPs:
Only support kind: string, bool, intX, uintX, floatX
Types ¶
type BKind ¶
type BKind uint
BKind base data kind type
func ToBaseKind ¶
ToBaseKind convert reflect.Kind to base kind
type Value ¶
Value struct
func (Value) Elem ¶
Elem returns the value that the interface v contains or that the pointer v points to.
TIP: not like reflect.Value.Elem. otherwise, will return self.