Documentation
¶
Overview ¶
Package reflect contains a collection of helpful generic functions that support reflection. It is currently not part of the public interface and must be consider as highly instable.
Index ¶
- Constants
- Variables
- func AnyFuncOf(args int, variadic bool) reflect.Type
- func ArgOf(v reflect.Value) any
- func ArgsOf(values ...reflect.Value) []any
- func BaseFuncOf(mtype reflect.Type, in, out int) reflect.Type
- func MakeFuncOf(mtype reflect.Type, call func([]reflect.Value) []reflect.Value) any
- func NewErrInvalidType(index int, expect, actual reflect.Type) error
- func StringArgs(args []any) []string
- func ValuesIn(ftype reflect.Type, args ...any) []reflect.Value
- func ValuesOut(ftype reflect.Type, lenient bool, args ...any) []reflect.Value
- type Kind
- type Random
- type Type
- type Value
Constants ¶
const ( // Invalid alias for `reflect.Invalid`. Invalid = reflect.Invalid // Bool alias for `reflect.Bool`. Bool = reflect.Bool // Int alias for `reflect.Int`. Int = reflect.Int // Int8 alias for `reflect.Int8`. Int8 = reflect.Int8 // Int16 alias for `reflect.Int16`. Int16 = reflect.Int16 // Int32 alias for `reflect.Int32`. Int32 = reflect.Int32 // Int64 alias for `reflect.Int64`. Int64 = reflect.Int64 // Uint alias for `reflect.Uint`. Uint = reflect.Uint // Uint8 alias for `reflect.Uint8`. Uint8 = reflect.Uint8 // Uint16 alias for `reflect.Uint16`. Uint16 = reflect.Uint16 // Uint32 alias for `reflect.Uint32`. Uint32 = reflect.Uint32 // Uint64 alias for `reflect.Uint64`. Uint64 = reflect.Uint64 // Uintptr alias for `reflect.Uintptr`. Uintptr = reflect.Uintptr // Float32 alias for `reflect.Float32`. Float32 = reflect.Float32 // Float64 alias for `reflect.Float64`. Float64 = reflect.Float64 // Complex64 alias for `reflect.Complex64`. Complex64 = reflect.Complex64 // Complex128 alias for `reflect.Complex128`. Complex128 = reflect.Complex128 // Array alias for `reflect.Array`. Array = reflect.Array // Chan alias for `reflect.Chan`. Chan = reflect.Chan // Func alias for `reflect.Func`. Func = reflect.Func // Interface alias for `reflect.Interface`. Interface = reflect.Interface // Map alias for `reflect.Map`. Map = reflect.Map // Pointer alias for `reflect.Pointer`. Pointer = reflect.Pointer // Slice alias for `reflect.Slice`. Slice = reflect.Slice // String alias for `reflect.String`. String = reflect.String // Struct alias for `reflect.Struct`. Struct = reflect.Struct // UnsafePointer alias for `reflect.UnsafePointer`. UnsafePointer = reflect.UnsafePointer )
Aliases for constant values.
Variables ¶
var ( // TypeOf alias for `reflect.TypeOf`. TypeOf = reflect.TypeOf // ValueOf alias for `reflect.ValueOf`. ValueOf = reflect.ValueOf // New alias for `reflect.New`. New = reflect.New // Zero alias for `reflect.Zero`. Zero = reflect.Zero // Ptr alias for `reflect.Ptr`. Ptr = reflect.Ptr // PointerTo alias for `reflect.PointerTo`. PointerTo = reflect.PointerTo )
Aliases for function values.
Functions ¶
func BaseFuncOf ¶
BaseFuncOf allows to extract a base function from an interface function containing no receiver and suppressing the return values - if necessary. The given `in` and `out` values allow to restrict the included input and output arguments. Use `1` to remove the first argument, or `NumIn/NumOut` to remove all arguments.
func MakeFuncOf ¶
MakeFuncOf returns a newly created function with given reflective function.
func NewErrInvalidType ¶
NewErrInvalidType creates a new error reporting an invalid type during value slice creation.
func StringArgs ¶ added in v0.0.32
StringArgs is a helper function that converts a slice of any to a slice of strings. The function is used only by the reporter package to format the function arguments in `UnexpectedCall` and `ConsumedCall` in the same way as the controller is doing it.
Unfortunately, this requires us to duplicate the internal controller logic here creating a brittle dependency on the implementation.
func ValuesIn ¶
ValuesIn returns the reflection values matching the input arguments of the given function.