package reflect

Import Path
	reflect (on golang.org and go.dev)

Dependency Relation
	imports 8 packages, and imported by 20 packages

Involved Source Files
	    deepequal.go
	    makefunc.go
	    swapper.go
	d-> type.go
	    value.go
	    asm_amd64.s

Exported Type Names

type ChanDir int ChanDir represents a channel type's direction. (T) String() string T : expvar.Var T : fmt.Stringer func Type.ChanDir() ChanDir func ChanOf(dir ChanDir, t Type) Type const BothDir const RecvDir const SendDir
type Kind uint A Kind represents the specific kind of type that a Type represents. The zero Kind is not a valid kind. (T) String() string T : expvar.Var T : fmt.Stringer func Type.Kind() Kind func Value.Kind() Kind const Array const Bool const Chan const Complex128 const Complex64 const Float32 const Float64 const Func const Int const Int16 const Int32 const Int64 const Int8 const Interface const Invalid const Map const Ptr const Slice const String const Struct const Uint const Uint16 const Uint32 const Uint64 const Uint8 const Uintptr const UnsafePointer
type MapIter (struct) A MapIter is an iterator for ranging over a map. See Value.MapRange. (*T) Key() Value (*T) Next() bool (*T) Value() Value func Value.MapRange() *MapIter
type Method (struct) Method represents a single method. Func Value Index int Name string PkgPath string Type Type func Type.Method(int) Method func Type.MethodByName(string) (Method, bool)
type SelectCase (struct) A SelectCase describes a single case in a select operation. The kind of case depends on Dir, the communication direction. If Dir is SelectDefault, the case represents a default case. Chan and Send must be zero Values. If Dir is SelectSend, the case represents a send operation. Normally Chan's underlying value must be a channel, and Send's underlying value must be assignable to the channel's element type. As a special case, if Chan is a zero Value, then the case is ignored, and the field Send will also be ignored and may be either zero or non-zero. If Dir is SelectRecv, the case represents a receive operation. Normally Chan's underlying value must be a channel and Send must be a zero Value. If Chan is a zero Value, then the case is ignored, but Send must still be a zero Value. When a receive operation is selected, the received Value is returned by Select. Chan Value Dir SelectDir Send Value func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)
type SelectDir int A SelectDir describes the communication direction of a select case. const SelectDefault const SelectRecv const SelectSend
type SliceHeader (struct) SliceHeader is the runtime representation of a slice. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data. Cap int Data uintptr Len int
type StringHeader (struct) StringHeader is the runtime representation of a string. It cannot be used safely or portably and its representation may change in a later release. Moreover, the Data field is not sufficient to guarantee the data it references will not be garbage collected, so programs must keep a separate, correctly typed pointer to the underlying data. Data uintptr Len int
type StructField (struct) A StructField describes a single field in a struct. Anonymous bool Index []int Name string Offset uintptr PkgPath string Tag StructTag Type Type func Type.Field(i int) StructField func Type.FieldByIndex(index []int) StructField func Type.FieldByName(name string) (StructField, bool) func Type.FieldByNameFunc(match func(string) bool) (StructField, bool) func StructOf(fields []StructField) Type
type StructTag string A StructTag is the tag string in a struct field. By convention, tag strings are a concatenation of optionally space-separated key:"value" pairs. Each key is a non-empty string consisting of non-control characters other than space (U+0020 ' '), quote (U+0022 '"'), and colon (U+003A ':'). Each value is quoted using U+0022 '"' characters and Go string literal syntax. (T) Get(key string) string (T) Lookup(key string) (value string, ok bool)
type Type (interface) Type is the representation of a Go type. Not all methods apply to all kinds of types. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of type before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run-time panic. Type values are comparable, such as with the == operator, so they can be used as map keys. Two Type values are equal if they represent identical types. (T) Align() int (T) AssignableTo(u Type) bool (T) Bits() int (T) ChanDir() ChanDir (T) Comparable() bool (T) ConvertibleTo(u Type) bool (T) Elem() Type (T) Field(i int) StructField (T) FieldAlign() int (T) FieldByIndex(index []int) StructField (T) FieldByName(name string) (StructField, bool) (T) FieldByNameFunc(match func(string) bool) (StructField, bool) (T) Implements(u Type) bool (T) In(i int) Type (T) IsVariadic() bool (T) Key() Type (T) Kind() Kind (T) Len() int (T) Method(int) Method (T) MethodByName(string) (Method, bool) (T) Name() string (T) NumField() int (T) NumIn() int (T) NumMethod() int (T) NumOut() int (T) Out(i int) Type (T) PkgPath() string (T) Size() uintptr (T) String() string T : expvar.Var T : fmt.Stringer func ArrayOf(count int, elem Type) Type func ChanOf(dir ChanDir, t Type) Type func FuncOf(in, out []Type, variadic bool) Type func MapOf(key, elem Type) Type func PtrTo(t Type) Type func SliceOf(t Type) Type func StructOf(fields []StructField) Type func TypeOf(i interface{}) Type func Type.Elem() Type func Type.In(i int) Type func Type.Key() Type func Type.Out(i int) Type func Value.Type() Type func database/sql.(*ColumnType).ScanType() Type func database/sql/driver.RowsColumnTypeScanType.ColumnTypeScanType(index int) Type func ArrayOf(count int, elem Type) Type func ChanOf(dir ChanDir, t Type) Type func FuncOf(in, out []Type, variadic bool) Type func MakeChan(typ Type, buffer int) Value func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value func MakeMap(typ Type) Value func MakeMapWithSize(typ Type, n int) Value func MakeSlice(typ Type, len, cap int) Value func MapOf(key, elem Type) Type func New(typ Type) Value func NewAt(typ Type, p unsafe.Pointer) Value func PtrTo(t Type) Type func SliceOf(t Type) Type func Zero(typ Type) Value func Type.AssignableTo(u Type) bool func Type.ConvertibleTo(u Type) bool func Type.Implements(u Type) bool func Value.Convert(t Type) Value func testing/quick.Value(t Type, rand *rand.Rand) (value Value, ok bool)
type Value (struct) Value is the reflection interface to a Go value. Not all methods apply to all kinds of values. Restrictions, if any, are noted in the documentation for each method. Use the Kind method to find out the kind of value before calling kind-specific methods. Calling a method inappropriate to the kind of type causes a run time panic. The zero Value represents no value. Its IsValid method returns false, its Kind method returns Invalid, its String method returns "<invalid Value>", and all other methods panic. Most functions and methods never return an invalid value. If one does, its documentation states the conditions explicitly. A Value can be used concurrently by multiple goroutines provided that the underlying Go value can be used concurrently for the equivalent direct operations. To compare two Values, compare the results of the Interface method. Using == on two Values does not compare the underlying values they represent. (T) Addr() Value (T) Bool() bool (T) Bytes() []byte (T) Call(in []Value) []Value (T) CallSlice(in []Value) []Value (T) CanAddr() bool (T) CanInterface() bool (T) CanSet() bool (T) Cap() int (T) Close() (T) Complex() complex128 (T) Convert(t Type) Value (T) Elem() Value (T) Field(i int) Value (T) FieldByIndex(index []int) Value (T) FieldByName(name string) Value (T) FieldByNameFunc(match func(string) bool) Value (T) Float() float64 (T) Index(i int) Value (T) Int() int64 (T) Interface() (i interface{}) (T) InterfaceData() [2]uintptr (T) IsNil() bool (T) IsValid() bool (T) IsZero() bool (T) Kind() Kind (T) Len() int (T) MapIndex(key Value) Value (T) MapKeys() []Value (T) MapRange() *MapIter (T) Method(i int) Value (T) MethodByName(name string) Value (T) NumField() int (T) NumMethod() int (T) OverflowComplex(x complex128) bool (T) OverflowFloat(x float64) bool (T) OverflowInt(x int64) bool (T) OverflowUint(x uint64) bool (T) Pointer() uintptr (T) Recv() (x Value, ok bool) (T) Send(x Value) (T) Set(x Value) (T) SetBool(x bool) (T) SetBytes(x []byte) (T) SetCap(n int) (T) SetComplex(x complex128) (T) SetFloat(x float64) (T) SetInt(x int64) (T) SetLen(n int) (T) SetMapIndex(key, elem Value) (T) SetPointer(x unsafe.Pointer) (T) SetString(x string) (T) SetUint(x uint64) (T) Slice(i, j int) Value (T) Slice3(i, j, k int) Value (T) String() string (T) TryRecv() (x Value, ok bool) (T) TrySend(x Value) bool (T) Type() Type (T) Uint() uint64 (T) UnsafeAddr() uintptr T : database/sql/driver.Validator T : expvar.Var T : fmt.Stringer func Append(s Value, x ...Value) Value func AppendSlice(s, t Value) Value func Indirect(v Value) Value func MakeChan(typ Type, buffer int) Value func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value func MakeMap(typ Type) Value func MakeMapWithSize(typ Type, n int) Value func MakeSlice(typ Type, len, cap int) Value func New(typ Type) Value func NewAt(typ Type, p unsafe.Pointer) Value func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool) func ValueOf(i interface{}) Value func Zero(typ Type) Value func (*MapIter).Key() Value func (*MapIter).Value() Value func Value.Addr() Value func Value.Call(in []Value) []Value func Value.CallSlice(in []Value) []Value func Value.Convert(t Type) Value func Value.Elem() Value func Value.Field(i int) Value func Value.FieldByIndex(index []int) Value func Value.FieldByName(name string) Value func Value.FieldByNameFunc(match func(string) bool) Value func Value.Index(i int) Value func Value.MapIndex(key Value) Value func Value.MapKeys() []Value func Value.Method(i int) Value func Value.MethodByName(name string) Value func Value.Recv() (x Value, ok bool) func Value.Slice(i, j int) Value func Value.Slice3(i, j, k int) Value func Value.TryRecv() (x Value, ok bool) func testing/quick.Value(t Type, rand *rand.Rand) (value Value, ok bool) func testing/quick.Generator.Generate(rand *rand.Rand, size int) Value func Append(s Value, x ...Value) Value func Append(s Value, x ...Value) Value func AppendSlice(s, t Value) Value func Copy(dst, src Value) int func Indirect(v Value) Value func Value.Call(in []Value) []Value func Value.CallSlice(in []Value) []Value func Value.MapIndex(key Value) Value func Value.Send(x Value) func Value.Set(x Value) func Value.SetMapIndex(key, elem Value) func Value.TrySend(x Value) bool func encoding/gob.(*Decoder).DecodeValue(v Value) error func encoding/gob.(*Encoder).EncodeValue(value Value) error func go/ast.NotNilFilter(_ string, v Value) bool func internal/fmtsort.Sort(mapValue Value) *fmtsort.SortedMap
type ValueError (struct) A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method. Kind Kind Method string (*T) Error() string *T : error
Exported Values
func Append(s Value, x ...Value) Value Append appends the values x to a slice s and returns the resulting slice. As in Go, each x's value must be assignable to the slice's element type.
func AppendSlice(s, t Value) Value AppendSlice appends a slice t to a slice s and returns the resulting slice. The slices s and t must have the same element type.
const Array Kind = 17
func ArrayOf(count int, elem Type) Type ArrayOf returns the array type with the given count and element type. For example, if t represents int, ArrayOf(5, t) represents [5]int. If the resulting type would be larger than the available address space, ArrayOf panics.
const Bool Kind = 1
const BothDir ChanDir = 3 // chan
const Chan Kind = 18
func ChanOf(dir ChanDir, t Type) Type ChanOf returns the channel type with the given direction and element type. For example, if t represents int, ChanOf(RecvDir, t) represents <-chan int. The gc runtime imposes a limit of 64 kB on channel element types. If t's size is equal to or exceeds this limit, ChanOf panics.
const Complex128 Kind = 16
const Complex64 Kind = 15
func Copy(dst, src Value) int Copy copies the contents of src into dst until either dst has been filled or src has been exhausted. It returns the number of elements copied. Dst and src each must have kind Slice or Array, and dst and src must have the same element type. As a special case, src can have kind String if the element type of dst is kind Uint8.
func DeepEqual(x, y interface{}) bool DeepEqual reports whether x and y are ``deeply equal,'' defined as follows. Two values of identical type are deeply equal if one of the following cases applies. Values of distinct types are never deeply equal. Array values are deeply equal when their corresponding elements are deeply equal. Struct values are deeply equal if their corresponding fields, both exported and unexported, are deeply equal. Func values are deeply equal if both are nil; otherwise they are not deeply equal. Interface values are deeply equal if they hold deeply equal concrete values. Map values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they are the same map object or their corresponding keys (matched using Go equality) map to deeply equal values. Pointer values are deeply equal if they are equal using Go's == operator or if they point to deeply equal values. Slice values are deeply equal when all of the following are true: they are both nil or both non-nil, they have the same length, and either they point to the same initial entry of the same underlying array (that is, &x[0] == &y[0]) or their corresponding elements (up to length) are deeply equal. Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil)) are not deeply equal. Other values - numbers, bools, strings, and channels - are deeply equal if they are equal using Go's == operator. In general DeepEqual is a recursive relaxation of Go's == operator. However, this idea is impossible to implement without some inconsistency. Specifically, it is possible for a value to be unequal to itself, either because it is of func type (uncomparable in general) or because it is a floating-point NaN value (not equal to itself in floating-point comparison), or because it is an array, struct, or interface containing such a value. On the other hand, pointer values are always equal to themselves, even if they point at or contain such problematic values, because they compare equal using Go's == operator, and that is a sufficient condition to be deeply equal, regardless of content. DeepEqual has been defined so that the same short-cut applies to slices and maps: if x and y are the same slice or the same map, they are deeply equal regardless of content. As DeepEqual traverses the data values it may find a cycle. The second and subsequent times that DeepEqual compares two pointer values that have been compared before, it treats the values as equal rather than examining the values to which they point. This ensures that DeepEqual terminates.
const Float32 Kind = 13
const Float64 Kind = 14
const Func Kind = 19
func FuncOf(in, out []Type, variadic bool) Type FuncOf returns the function type with the given argument and result types. For example if k represents int and e represents string, FuncOf([]Type{k}, []Type{e}, false) represents func(int) string. The variadic argument controls whether the function is variadic. FuncOf panics if the in[len(in)-1] does not represent a slice and variadic is true.
func Indirect(v Value) Value Indirect returns the value that v points to. If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v.
const Int Kind = 2
const Int16 Kind = 4
const Int32 Kind = 5
const Int64 Kind = 6
const Int8 Kind = 3
const Interface Kind = 20
const Invalid Kind = 0
func MakeChan(typ Type, buffer int) Value MakeChan creates a new channel with the specified type and buffer size.
func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value MakeFunc returns a new function of the given Type that wraps the function fn. When called, that new function does the following: - converts its arguments to a slice of Values. - runs results := fn(args). - returns the results as a slice of Values, one per formal result. The implementation fn can assume that the argument Value slice has the number and type of arguments given by typ. If typ describes a variadic function, the final Value is itself a slice representing the variadic arguments, as in the body of a variadic function. The result Value slice returned by fn must have the number and type of results given by typ. The Value.Call method allows the caller to invoke a typed function in terms of Values; in contrast, MakeFunc allows the caller to implement a typed function in terms of Values. The Examples section of the documentation includes an illustration of how to use MakeFunc to build a swap function for different types.
func MakeMap(typ Type) Value MakeMap creates a new map with the specified type.
func MakeMapWithSize(typ Type, n int) Value MakeMapWithSize creates a new map with the specified type and initial space for approximately n elements.
func MakeSlice(typ Type, len, cap int) Value MakeSlice creates a new zero-initialized slice value for the specified slice type, length, and capacity.
const Map Kind = 21
func MapOf(key, elem Type) Type MapOf returns the map type with the given key and element types. For example, if k represents int and e represents string, MapOf(k, e) represents map[int]string. If the key type is not a valid map key type (that is, if it does not implement Go's == operator), MapOf panics.
func New(typ Type) Value New returns a Value representing a pointer to a new zero value for the specified type. That is, the returned Value's Type is PtrTo(typ).
func NewAt(typ Type, p unsafe.Pointer) Value NewAt returns a Value representing a pointer to a value of the specified type, using p as that pointer.
const Ptr Kind = 22
func PtrTo(t Type) Type PtrTo returns the pointer type with element t. For example, if t represents type Foo, PtrTo(t) represents *Foo.
const RecvDir ChanDir = 1 // <-chan
func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool) Select executes a select operation described by the list of cases. Like the Go select statement, it blocks until at least one of the cases can proceed, makes a uniform pseudo-random choice, and then executes that case. It returns the index of the chosen case and, if that case was a receive operation, the value received and a boolean indicating whether the value corresponds to a send on the channel (as opposed to a zero value received because the channel is closed). Select supports a maximum of 65536 cases.
const SelectDefault SelectDir = 3 // default
const SelectRecv SelectDir = 2 // case <-Chan:
const SelectSend SelectDir = 1 // case Chan <- Send
const SendDir ChanDir = 2 // chan<-
const Slice Kind = 23
func SliceOf(t Type) Type SliceOf returns the slice type with element type t. For example, if t represents int, SliceOf(t) represents []int.
const String Kind = 24
const Struct Kind = 25
func StructOf(fields []StructField) Type StructOf returns the struct type containing fields. The Offset and Index fields are ignored and computed as they would be by the compiler. StructOf currently does not generate wrapper methods for embedded fields and panics if passed unexported StructFields. These limitations may be lifted in a future version.
func Swapper(slice interface{}) func(i, j int) Swapper returns a function that swaps the elements in the provided slice. Swapper panics if the provided interface is not a slice.
func TypeOf(i interface{}) Type TypeOf returns the reflection Type that represents the dynamic type of i. If i is a nil interface value, TypeOf returns nil.
const Uint Kind = 7
const Uint16 Kind = 9
const Uint32 Kind = 10
const Uint64 Kind = 11
const Uint8 Kind = 8
const Uintptr Kind = 12
const UnsafePointer Kind = 26
func ValueOf(i interface{}) Value ValueOf returns a new Value initialized to the concrete value stored in the interface i. ValueOf(nil) returns the zero Value.
func Zero(typ Type) Value Zero returns a Value representing the zero value for the specified type. The result is different from the zero value of the Value struct, which represents no value at all. For example, Zero(TypeOf(42)) returns a Value with Kind Int and value 0. The returned value is neither addressable nor settable.