reflect

package
v0.0.51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
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

View Source
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 AnyFuncOf

func AnyFuncOf(args int, variadic bool) reflect.Type

AnyFuncOf returns a function with given number of arguments accepting any type.

func ArgOf

func ArgOf(v reflect.Value) any

ArgOf returns the argument of the given value.

func ArgsOf

func ArgsOf(values ...reflect.Value) []any

ArgsOf returns the arguments slice for the given values.

func BaseFuncOf

func BaseFuncOf(mtype reflect.Type, in, out int) reflect.Type

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

func MakeFuncOf(
	mtype reflect.Type, call func([]reflect.Value) []reflect.Value,
) any

MakeFuncOf returns a newly created function with given reflective function.

func NewErrInvalidType

func NewErrInvalidType(index int, expect, actual reflect.Type) error

NewErrInvalidType creates a new error reporting an invalid type during value slice creation.

func StringArgs added in v0.0.32

func StringArgs(args []any) []string

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

func ValuesIn(ftype reflect.Type, args ...any) []reflect.Value

ValuesIn returns the reflection values matching the input arguments of the given function.

func ValuesOut

func ValuesOut(ftype reflect.Type, lenient bool, args ...any) []reflect.Value

ValuesOut returns the reflection values matching the output arguments of the given function. If lenient is set, non existing output arguments are filled with zero values to support incomplete argument lists.

Types

type Kind added in v0.0.49

type Kind = reflect.Kind

Kind alias for `reflect.Kind`.

type Random added in v0.0.36

type Random interface {
	Random(obj any) any
}

Random is an interface for generating random data structures.

func NewRandom added in v0.0.36

func NewRandom(seed int64, size, length int) Random

NewRandom creates a random generator with default size and length limits.

type Type

type Type = reflect.Type

Type alias for `reflect.Type`.

type Value

type Value = reflect.Value

Value alias for `reflect.Value`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL