Documentation ¶
Overview ¶
Package reflectx contains a set of reflection utilities and well-known types.
Index ¶
- Variables
- func CallNoPanic(fn Func, args []interface{}) (ret []interface{}, err error)
- func FindTaggedField(t reflect.Type, values ...string) (reflect.StructField, bool)
- func FunctionName(fn interface{}) string
- func HasTag(f reflect.StructField, values ...string) bool
- func HasTaggedField(t reflect.Type, values ...string) bool
- func Interface(list []reflect.Value) []interface{}
- func IsComplex(t reflect.Type) bool
- func IsFloat(t reflect.Type) bool
- func IsInteger(t reflect.Type) bool
- func IsNumber(t reflect.Type) bool
- func LoadFunction(ptr uintptr, t reflect.Type) interface{}
- func MakeSlice(t reflect.Type, values ...reflect.Value) reflect.Value
- func RegisterFunc(t reflect.Type, maker func(interface{}) Func)
- func SetFieldValue(s reflect.Value, f reflect.StructField, value reflect.Value)
- func SetTaggedFieldValue(v reflect.Value, tag string, value reflect.Value)
- func SkipPtr(t reflect.Type) reflect.Type
- func UnderlyingType(value reflect.Value) reflect.Value
- func UnmarshalJSON(t reflect.Type, str string) (interface{}, error)
- func ValueOf(list []interface{}) []reflect.Value
- type Func
- type Func0x0
- type Func0x1
- type Func0x2
- type Func0x3
- type Func1x0
- type Func1x1
- type Func1x2
- type Func1x3
- type Func2x0
- type Func2x1
- type Func2x2
- type Func2x3
- type Func3x0
- type Func3x1
- type Func3x2
- type Func3x3
- type Func4x0
- type Func4x1
- type Func4x2
- type Func4x3
- type Func5x0
- type Func5x1
- type Func5x2
- type Func5x3
- type Func6x0
- type Func6x1
- type Func6x2
- type Func6x3
- type Func7x0
- type Func7x1
- type Func7x2
- type Func7x3
Constants ¶
This section is empty.
Variables ¶
var ( Bool = reflect.TypeOf((*bool)(nil)).Elem() Int = reflect.TypeOf((*int)(nil)).Elem() Int8 = reflect.TypeOf((*int8)(nil)).Elem() Int16 = reflect.TypeOf((*int16)(nil)).Elem() Int32 = reflect.TypeOf((*int32)(nil)).Elem() Int64 = reflect.TypeOf((*int64)(nil)).Elem() Uint = reflect.TypeOf((*uint)(nil)).Elem() Uint8 = reflect.TypeOf((*uint8)(nil)).Elem() Uint16 = reflect.TypeOf((*uint16)(nil)).Elem() Uint32 = reflect.TypeOf((*uint32)(nil)).Elem() Uint64 = reflect.TypeOf((*uint64)(nil)).Elem() Float32 = reflect.TypeOf((*float32)(nil)).Elem() Float64 = reflect.TypeOf((*float64)(nil)).Elem() String = reflect.TypeOf((*string)(nil)).Elem() Error = reflect.TypeOf((*error)(nil)).Elem() Context = reflect.TypeOf((*context.Context)(nil)).Elem() Type = reflect.TypeOf((*reflect.Type)(nil)).Elem() ByteSlice = reflect.TypeOf((*[]byte)(nil)).Elem() )
Well-known reflected types. Convenience definitions.
Functions ¶
func CallNoPanic ¶
CallNoPanic calls the given Func and catches any panic.
func FindTaggedField ¶
FindTaggedField returns the field tagged with any of the given tag values, if any. The tags are all under the "beam" StructTag key.
func FunctionName ¶
func FunctionName(fn interface{}) string
FunctionName returns the symbol name of a function. It panics if the given value is not a function.
func HasTag ¶
func HasTag(f reflect.StructField, values ...string) bool
HasTag returns true iff the given field contains one of the given tags under the "beam" key.
func HasTaggedField ¶
HasTaggedField returns true iff the given struct has a field with any of the given tag values.
func IsInteger ¶
IsInteger returns true iff the given type is an integer, such as uint16, int, or int64.
func LoadFunction ¶
LoadFunction loads a function from a pointer and type. Assumes the pointer points to a valid function implementation.
func RegisterFunc ¶
RegisterFunc registers an custom Func factory for the given type, such as "func(int)bool". If multiple Func factories are registered for the same type, the last registration wins.
func SetFieldValue ¶
SetFieldValue sets s.f = value. Panics if not valid.
func SetTaggedFieldValue ¶
SetTaggedFieldValue sets s.f = value, where f has the tag "beam:tag". Panics if not valid.
func UnderlyingType ¶
UnderlyingType drops value's type by converting it to an interface and then returning ValueOf() the untyped value.
func UnmarshalJSON ¶
UnmarshalJSON decodes a json string as then given type. It is suitable for when the type is not statically known.
Types ¶
type Func ¶
type Func interface { // Name returns the name of the function. Name() string // Type returns the type. Type() reflect.Type // Call invokes the implicit fn with arguments. Call(args []interface{}) []interface{} }
Func represents a callable untyped function. This indirection allows us to avoid reflection call overhead for certain types as well as faster dynamic function implementations.
type Func0x0 ¶
type Func0x0 interface { Func Call0x0() }
func MakeFunc0x0 ¶
func MakeFunc0x0(fn interface{}) Func0x0
type Func0x1 ¶
type Func0x1 interface { Func Call0x1() interface{} }
func MakeFunc0x1 ¶
func MakeFunc0x1(fn interface{}) Func0x1
type Func0x2 ¶
type Func0x2 interface { Func Call0x2() (interface{}, interface{}) }
func MakeFunc0x2 ¶
func MakeFunc0x2(fn interface{}) Func0x2
type Func0x3 ¶
type Func0x3 interface { Func Call0x3() (interface{}, interface{}, interface{}) }
func MakeFunc0x3 ¶
func MakeFunc0x3(fn interface{}) Func0x3
type Func1x0 ¶
type Func1x0 interface { Func Call1x0(interface{}) }
func MakeFunc1x0 ¶
func MakeFunc1x0(fn interface{}) Func1x0
type Func1x1 ¶
type Func1x1 interface { Func Call1x1(interface{}) interface{} }
func MakeFunc1x1 ¶
func MakeFunc1x1(fn interface{}) Func1x1
type Func1x2 ¶
type Func1x2 interface { Func Call1x2(interface{}) (interface{}, interface{}) }
func MakeFunc1x2 ¶
func MakeFunc1x2(fn interface{}) Func1x2
type Func1x3 ¶
type Func1x3 interface { Func Call1x3(interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc1x3 ¶
func MakeFunc1x3(fn interface{}) Func1x3
type Func2x0 ¶
type Func2x0 interface { Func Call2x0(interface{}, interface{}) }
func MakeFunc2x0 ¶
func MakeFunc2x0(fn interface{}) Func2x0
type Func2x1 ¶
type Func2x1 interface { Func Call2x1(interface{}, interface{}) interface{} }
func MakeFunc2x1 ¶
func MakeFunc2x1(fn interface{}) Func2x1
type Func2x2 ¶
type Func2x2 interface { Func Call2x2(interface{}, interface{}) (interface{}, interface{}) }
func MakeFunc2x2 ¶
func MakeFunc2x2(fn interface{}) Func2x2
type Func2x3 ¶
type Func2x3 interface { Func Call2x3(interface{}, interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc2x3 ¶
func MakeFunc2x3(fn interface{}) Func2x3
type Func3x0 ¶
type Func3x0 interface { Func Call3x0(interface{}, interface{}, interface{}) }
func MakeFunc3x0 ¶
func MakeFunc3x0(fn interface{}) Func3x0
type Func3x1 ¶
type Func3x1 interface { Func Call3x1(interface{}, interface{}, interface{}) interface{} }
func MakeFunc3x1 ¶
func MakeFunc3x1(fn interface{}) Func3x1
type Func3x2 ¶
type Func3x2 interface { Func Call3x2(interface{}, interface{}, interface{}) (interface{}, interface{}) }
func MakeFunc3x2 ¶
func MakeFunc3x2(fn interface{}) Func3x2
type Func3x3 ¶
type Func3x3 interface { Func Call3x3(interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc3x3 ¶
func MakeFunc3x3(fn interface{}) Func3x3
type Func4x0 ¶
type Func4x0 interface { Func Call4x0(interface{}, interface{}, interface{}, interface{}) }
func MakeFunc4x0 ¶
func MakeFunc4x0(fn interface{}) Func4x0
type Func4x1 ¶
type Func4x1 interface { Func Call4x1(interface{}, interface{}, interface{}, interface{}) interface{} }
func MakeFunc4x1 ¶
func MakeFunc4x1(fn interface{}) Func4x1
type Func4x2 ¶
type Func4x2 interface { Func Call4x2(interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
func MakeFunc4x2 ¶
func MakeFunc4x2(fn interface{}) Func4x2
type Func4x3 ¶
type Func4x3 interface { Func Call4x3(interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc4x3 ¶
func MakeFunc4x3(fn interface{}) Func4x3
type Func5x0 ¶
type Func5x0 interface { Func Call5x0(interface{}, interface{}, interface{}, interface{}, interface{}) }
func MakeFunc5x0 ¶
func MakeFunc5x0(fn interface{}) Func5x0
type Func5x1 ¶
type Func5x1 interface { Func Call5x1(interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }
func MakeFunc5x1 ¶
func MakeFunc5x1(fn interface{}) Func5x1
type Func5x2 ¶
type Func5x2 interface { Func Call5x2(interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
func MakeFunc5x2 ¶
func MakeFunc5x2(fn interface{}) Func5x2
type Func5x3 ¶
type Func5x3 interface { Func Call5x3(interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc5x3 ¶
func MakeFunc5x3(fn interface{}) Func5x3
type Func6x0 ¶
type Func6x0 interface { Func Call6x0(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) }
func MakeFunc6x0 ¶
func MakeFunc6x0(fn interface{}) Func6x0
type Func6x1 ¶
type Func6x1 interface { Func Call6x1(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }
func MakeFunc6x1 ¶
func MakeFunc6x1(fn interface{}) Func6x1
type Func6x2 ¶
type Func6x2 interface { Func Call6x2(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}) }
func MakeFunc6x2 ¶
func MakeFunc6x2(fn interface{}) Func6x2
type Func6x3 ¶
type Func6x3 interface { Func Call6x3(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) (interface{}, interface{}, interface{}) }
func MakeFunc6x3 ¶
func MakeFunc6x3(fn interface{}) Func6x3
type Func7x0 ¶
type Func7x0 interface { Func Call7x0(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) }
func MakeFunc7x0 ¶
func MakeFunc7x0(fn interface{}) Func7x0
type Func7x1 ¶
type Func7x1 interface { Func Call7x1(interface{}, interface{}, interface{}, interface{}, interface{}, interface{}, interface{}) interface{} }
func MakeFunc7x1 ¶
func MakeFunc7x1(fn interface{}) Func7x1