Documentation
¶
Index ¶
- Constants
- func Copy(dst, src Value) int
- func DeepEqual(x, y interface{}) bool
- func Swapper(slice interface{}) func(i, j int)
- type ChanDir
- type Kind
- type MapIter
- type RawType
- func (t *RawType) Align() int
- func (t *RawType) AssignableTo(u Type) bool
- func (t *RawType) Bits() int
- func (t *RawType) ChanDir() ChanDir
- func (t *RawType) Comparable() bool
- func (t *RawType) Elem() Type
- func (t *RawType) Field(i int) StructField
- func (t *RawType) FieldAlign() int
- func (t *RawType) FieldByIndex(index []int) StructField
- func (t *RawType) FieldByName(name string) (StructField, bool)
- func (t *RawType) FieldByNameFunc(match func(string) bool) (StructField, bool)
- func (t *RawType) Implements(u Type) bool
- func (t *RawType) Key() Type
- func (t *RawType) Kind() Kind
- func (t *RawType) Len() int
- func (t *RawType) Name() string
- func (t *RawType) NumField() int
- func (t *RawType) NumMethod() int
- func (t RawType) OverflowComplex(x complex128) bool
- func (t RawType) OverflowFloat(x float64) bool
- func (t RawType) OverflowInt(x int64) bool
- func (t RawType) OverflowUint(x uint64) bool
- func (t *RawType) PkgPath() string
- func (t *RawType) Size() uintptr
- func (t *RawType) String() string
- type StructField
- type StructTag
- type Type
- type TypeError
- type Value
- func Append(v Value, x ...Value) Value
- func AppendSlice(s, t Value) Value
- func Indirect(v 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 ValueOf(i interface{}) Value
- func Zero(typ Type) Value
- func (v Value) Addr() Value
- func (v Value) Bool() bool
- func (v Value) Bytes() []byte
- func (v Value) Call(in []Value) []Value
- func (v Value) CallSlice(in []Value) []Value
- func (v Value) CanAddr() bool
- func (v Value) CanComplex() bool
- func (v Value) CanConvert(t Type) bool
- func (v Value) CanFloat() bool
- func (v Value) CanInt() bool
- func (v Value) CanInterface() bool
- func (v Value) CanSet() bool
- func (v Value) CanUint() bool
- func (v Value) Cap() int
- func (v Value) Clear()
- func (v Value) Comparable() bool
- func (v Value) Complex() complex128
- func (v Value) Convert(t Type) Value
- func (v Value) Elem() Value
- func (v Value) Equal(u Value) bool
- func (v Value) Field(i int) Value
- func (v Value) FieldByIndex(index []int) Value
- func (v Value) FieldByIndexErr(index []int) (Value, error)
- func (v Value) FieldByName(name string) Value
- func (v Value) FieldByNameFunc(match func(string) bool) Value
- func (v Value) Float() float64
- func (v Value) Float32() float32
- func (v Value) Grow(n int)
- func (v Value) Index(i int) Value
- func (v Value) Int() int64
- func (v Value) Interface() interface{}
- func (v Value) IsNil() bool
- func (v Value) IsValid() bool
- func (v Value) IsZero() bool
- func (v Value) Kind() Kind
- func (v Value) Len() int
- func (v Value) MapIndex(key Value) Value
- func (v Value) MapKeys() []Value
- func (v Value) MapRange() *MapIter
- func (v Value) Method(i int) Value
- func (v Value) MethodByName(name string) Value
- func (v Value) NumField() int
- func (v Value) NumMethod() int
- func (v Value) OverflowFloat(x float64) bool
- func (v Value) OverflowInt(x int64) bool
- func (v Value) OverflowUint(x uint64) bool
- func (v Value) Pointer() uintptr
- func (v Value) RawType() *RawType
- func (v Value) Recv() (x Value, ok bool)
- func (v Value) Set(x Value)
- func (v Value) SetBool(x bool)
- func (v Value) SetBytes(x []byte)
- func (v Value) SetCap(n int)
- func (v Value) SetComplex(x complex128)
- func (v Value) SetFloat(x float64)
- func (v Value) SetInt(x int64)
- func (v Value) SetIterKey(iter *MapIter)
- func (v Value) SetIterValue(iter *MapIter)
- func (v Value) SetLen(n int)
- func (v Value) SetMapIndex(key, elem Value)
- func (v Value) SetString(x string)
- func (v Value) SetUint(x uint64)
- func (v Value) SetZero()
- func (v Value) Slice(i, j int) Value
- func (v Value) Slice3(i, j, k int) Value
- func (v Value) String() string
- func (v Value) Type() Type
- func (v Value) Uint() uint64
- func (v Value) UnsafeAddr() uintptr
- func (v Value) UnsafePointer() unsafe.Pointer
- type ValueError
Constants ¶
const Ptr = Pointer
Ptr is the old name for the Pointer kind.
Variables ¶
This section is empty.
Functions ¶
func Copy ¶ added in v0.37.0
Copy copies the contents of src into dst until either dst has been filled or src has been exhausted.
func DeepEqual ¶ added in v0.37.0
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.
Types ¶
type Kind ¶
type Kind uint8
const ( Invalid Kind = iota Bool Int Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Uintptr Float32 Float64 Complex64 Complex128 String UnsafePointer Chan Interface Pointer Slice Array Func Map Struct )
Copied from reflect/type.go https://golang.org/src/reflect/type.go?s=8302:8316#L217 These constants must match basicTypes and the typeKind* constants in compiler/interface.go
type RawType ¶ added in v0.37.0
type RawType struct {
// contains filtered or unexported fields
}
The base type struct. All type structs start with this.
func (*RawType) Align ¶ added in v0.37.0
Align returns the alignment of this type. It is similar to calling unsafe.Alignof.
func (*RawType) AssignableTo ¶ added in v0.37.0
AssignableTo returns whether a value of type t can be assigned to a variable of type u.
func (*RawType) Bits ¶ added in v0.37.0
Bits returns the number of bits that this type uses. It is only valid for arithmetic types (integers, floats, and complex numbers). For other types, it will panic.
func (*RawType) Comparable ¶ added in v0.37.0
Comparable returns whether values of this type can be compared to each other.
func (*RawType) Elem ¶ added in v0.37.0
Elem returns the element type for channel, slice and array types, the pointed-to value for pointer types, and the key type for map types.
func (*RawType) Field ¶ added in v0.37.0
func (t *RawType) Field(i int) StructField
Field returns the type of the i'th field of this struct type. It panics if t is not a struct type.
func (*RawType) FieldAlign ¶ added in v0.37.0
FieldAlign returns the alignment if this type is used in a struct field. It is currently an alias for Align() but this might change in the future.
func (*RawType) FieldByIndex ¶ added in v0.37.0
func (t *RawType) FieldByIndex(index []int) StructField
func (*RawType) FieldByName ¶ added in v0.37.0
func (t *RawType) FieldByName(name string) (StructField, bool)
func (*RawType) FieldByNameFunc ¶ added in v0.37.0
func (t *RawType) FieldByNameFunc(match func(string) bool) (StructField, bool)
func (*RawType) Implements ¶ added in v0.37.0
func (*RawType) Len ¶ added in v0.37.0
Len returns the number of elements in this array. It panics of the type kind is not Array.
func (*RawType) NumField ¶ added in v0.37.0
NumField returns the number of fields of a struct type. It panics for other type kinds.
func (RawType) OverflowComplex ¶ added in v0.37.0
func (t RawType) OverflowComplex(x complex128) bool
OverflowComplex reports whether the complex128 x cannot be represented by type t. It panics if t's Kind is not Complex64 or Complex128.
func (RawType) OverflowFloat ¶ added in v0.37.0
OverflowFloat reports whether the float64 x cannot be represented by type t. It panics if t's Kind is not Float32 or Float64.
func (RawType) OverflowInt ¶ added in v0.37.0
OverflowInt reports whether the int64 x cannot be represented by type t. It panics if t's Kind is not Int, Int8, Int16, Int32, or Int64.
func (RawType) OverflowUint ¶ added in v0.37.0
OverflowUint reports whether the uint64 x cannot be represented by type t. It panics if t's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
type StructField ¶ added in v0.37.0
type StructField struct { // Name indicates the field name. Name string // PkgPath is the package path where the struct containing this field is // declared for unexported fields, or the empty string for exported fields. PkgPath string Type Type Tag StructTag // field tag string Offset uintptr Index []int // index sequence for Type.FieldByIndex Anonymous bool }
A StructField describes a single field in a struct. This must be kept in sync with reflect.StructField.
func VisibleFields ¶ added in v0.37.0
func VisibleFields(t Type) []StructField
VisibleFields returns all the visible fields in t, which must be a struct type. A field is defined as visible if it's accessible directly with a FieldByName call. The returned fields include fields inside anonymous struct members and unexported fields. They follow the same order found in the struct, with anonymous fields followed immediately by their promoted fields.
For each element e of the returned slice, the corresponding field can be retrieved from a value v of type t by calling v.FieldByIndex(e.Index).
func (StructField) IsExported ¶ added in v0.37.0
func (f StructField) IsExported() bool
IsExported reports whether the field is exported.
type StructTag ¶ added in v0.37.0
type StructTag string
A StructTag is the tag string in a struct field.
type Type ¶
type Type interface { // These should match the reflectlite.Type implementation in Go. AssignableTo(u Type) bool Comparable() bool Elem() Type Implements(u Type) bool Kind() Kind Name() string PkgPath() string Size() uintptr String() string // Additional methods shared with reflect.Type. Align() int Field(i int) StructField Key() Type Len() int NumField() int NumMethod() int }
Type represents the minimal interface for a Go type.
func StructOf ¶ added in v0.37.0
func StructOf([]StructField) Type
type TypeError ¶ added in v0.37.0
type TypeError struct {
Method string
}
TypeError is the error that is used in a panic when invoking a method on a type that is not applicable to that type.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
func Append ¶ added in v0.37.0
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 ¶ added in v0.37.0
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.
func MakeMapWithSize ¶ added in v0.37.0
MakeMapWithSize creates a new map with the specified type and initial space for approximately n elements.
func New ¶ added in v0.37.0
New is the reflect equivalent of the new(T) keyword, returning a pointer to a new value of the given type.
func (Value) CanComplex ¶ added in v0.37.0
CanComplex reports whether Complex can be used without panicking.
func (Value) CanConvert ¶ added in v0.37.0
func (Value) CanFloat ¶ added in v0.37.0
CanFloat reports whether Float can be used without panicking.
func (Value) CanInterface ¶ added in v0.37.0
func (Value) Cap ¶ added in v0.37.0
Cap returns the capacity of this value for arrays, channels and slices. For other types, it panics.
func (Value) Clear ¶ added in v0.37.0
func (v Value) Clear()
Clear clears the contents of a map or zeros the contents of a slice
It panics if v's Kind is not Map or Slice.
func (Value) Comparable ¶ added in v0.37.0
func (Value) Complex ¶ added in v0.37.0
func (v Value) Complex() complex128
func (Value) Equal ¶ added in v0.37.0
Equal reports true if v is equal to u. For two invalid values, Equal will report true. For an interface value, Equal will compare the value within the interface. Otherwise, If the values have different types, Equal will report false. Otherwise, for arrays and structs Equal will compare each element in order, and report false if it finds non-equal elements. During all comparisons, if values of the same type are compared, and the type is not comparable, Equal will panic.
Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
func (Value) FieldByIndex ¶ added in v0.37.0
FieldByIndex returns the nested field corresponding to index.
func (Value) FieldByIndexErr ¶ added in v0.37.0
FieldByIndexErr returns the nested field corresponding to index.
func (Value) FieldByName ¶ added in v0.37.0
func (Value) FieldByNameFunc ¶ added in v0.37.0
func (Value) Grow ¶ added in v0.37.0
Grow increases the slice's capacity, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the slice without another allocation.
It panics if v's Kind is not a Slice or if n is negative or too large to allocate the memory.
func (Value) IsNil ¶ added in v0.37.0
IsNil returns whether the value is the nil value. It panics if the value Kind is not a channel, map, pointer, function, slice, or interface.
func (Value) IsZero ¶ added in v0.37.0
IsZero reports whether v is the zero value for its type. It panics if the argument is invalid.
func (Value) Len ¶ added in v0.37.0
Len returns the length of this value for slices, strings, arrays, channels, and maps. For other types, it panics.
func (Value) MethodByName ¶ added in v0.37.0
func (Value) NumField ¶ added in v0.37.0
NumField returns the number of fields of this struct. It panics for other value types.
func (Value) OverflowFloat ¶ added in v0.37.0
OverflowFloat reports whether the float64 x cannot be represented by v's type. It panics if v's Kind is not Float32 or Float64.
func (Value) OverflowInt ¶ added in v0.37.0
OverflowInt reports whether the int64 x cannot be represented by v's type. It panics if v's Kind is not Int, Int8, Int16, Int32, or Int64.
func (Value) OverflowUint ¶ added in v0.37.0
OverflowUint reports whether the uint64 x cannot be represented by v's type. It panics if v's Kind is not Uint, Uintptr, Uint8, Uint16, Uint32, or Uint64.
func (Value) Pointer ¶ added in v0.37.0
Pointer returns the underlying pointer of the given value for the following types: chan, map, pointer, unsafe.Pointer, slice, func.
func (Value) RawType ¶ added in v0.37.0
Internal function only, do not use.
RawType returns the raw, underlying type code. It is used in the runtime package and needs to be exported for the runtime package to access it.
func (Value) SetComplex ¶ added in v0.37.0
func (v Value) SetComplex(x complex128)
func (Value) SetIterKey ¶ added in v0.37.0
func (Value) SetIterValue ¶ added in v0.37.0
func (Value) SetMapIndex ¶ added in v0.37.0
func (Value) UnsafeAddr ¶ added in v0.37.0
func (Value) UnsafePointer ¶ added in v0.37.0
UnsafePointer returns the underlying pointer of the given value for the following types: chan, map, pointer, unsafe.Pointer, slice, func.
type ValueError ¶
func (*ValueError) Error ¶ added in v0.37.0
func (e *ValueError) Error() string