亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜尋
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數據結構heap) container/list(容器數據結構list) container/ring(容器數據結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數據庫/sql) database/sql/driver(數據庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "reflect"

  • 概述

  • 索引

概述

reflect 包了實現運行時反射,允許程序使用任意類型操作對象。典型的用法是用靜態(tài)類型接口{}取值并通過調用返回類型的 TypeOf 來提取其動態(tài)類型信息。

對 ValueOf 的調用返回表示運行時數據的值。Zero 采用 Type 并返回表示該類型的零值的 Value 。

索引

  • func Copy(dst, src Value) int

  • func DeepEqual(x, y interface{}) bool

  • func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)

  • func Swapper(slice interface{}) func(i, j int)

  • type ChanDir

  • func (d ChanDir) String() string

  • type Kind

  • func (k Kind) String() string

  • type Method

  • type SelectCase

  • type SelectDir

  • type SliceHeader

  • type StringHeader

  • type StructField

  • type StructTag

  • func (tag StructTag) Get(key string) string

  • func (tag StructTag) Lookup(key string) (value string, ok bool)

  • type Type

  • 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

  • type Value

  • 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 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) CanInterface() bool

  • func (v Value) CanSet() bool

  • func (v Value) Cap() int

  • func (v Value) Close()

  • func (v Value) Complex() complex128

  • func (v Value) Convert(t Type) Value

  • func (v Value) Elem() Value

  • func (v Value) Field(i int) Value

  • func (v Value) FieldByIndex(index []int) Value

  • func (v Value) FieldByName(name string) Value

  • func (v Value) FieldByNameFunc(match func(string) bool) Value

  • func (v Value) Float() float64

  • func (v Value) Index(i int) Value

  • func (v Value) Int() int64

  • func (v Value) Interface() (i interface{})

  • func (v Value) InterfaceData() [2]uintptr

  • func (v Value) IsNil() bool

  • func (v Value) IsValid() 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) Method(i int) Value

  • func (v Value) MethodByName(name string) Value

  • func (v Value) NumField() int

  • func (v Value) NumMethod() int

  • func (v Value) OverflowComplex(x complex128) bool

  • 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) Recv() (x Value, ok bool)

  • func (v Value) Send(x Value)

  • 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) SetLen(n int)

  • func (v Value) SetMapIndex(key, val Value)

  • func (v Value) SetPointer(x unsafe.Pointer)

  • func (v Value) SetString(x string)

  • func (v Value) SetUint(x uint64)

  • 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) TryRecv() (x Value, ok bool)

  • func (v Value) TrySend(x Value) bool

  • func (v Value) Type() Type

  • func (v Value) Uint() uint64

  • func (v Value) UnsafeAddr() uintptr

  • type ValueError

  • func (e *ValueError) Error() string

  • Bugs

文件包

deepequal.go makefunc.go swapper.go type.go value.go

func Copy

func Copy(dst, src Value) int

復制將 src 的內容復制到 dst ,直到 dst 被填充或 src 已用盡。它返回復制元素的數量。Dst 和 src 都必須有 Slice 或 Array 類型,而 dst 和 src 必須具有相同的元素類型。

func DeepEqual

func DeepEqual(x, y interface{}) bool

DeepEqual 報告 x 和 y 是否 “deeply equal” ,定義如下。如果以下情況之一適用,相同類型的兩個值是非常相等的。不同類型的值永遠不會相等。

當它們的對應元素非常相等時,數組值是非常相等的。

如果它們的導出和未導出的相應字段深度相等,那么結構值是相等的。

如果兩者均為零,則 Func 值非常相等;否則他們并不是很平等。

如果接口值具有深刻的等于具體值,則接口值是相等的。

當滿足以下所有條件時,地圖值是完全相同的:它們都是零或兩者都是非零,它們具有相同的長度,并且它們是相同的地圖對象或它們對應的鍵(使用 Go 相等匹配)映射到深度相等的價值。

如果使用 Go 的==運算符或者指向深度相等的值,則指針值相等,如果它們相等則指針值相等。

當滿足以下所有條件時,slice 值是相等的:它們都是零或者都是非零,它們具有相同的長度,并且它們指向相同基礎數組的相同初始條目(即&x0 == &y0)或其相應的元素(長度)是非常相等的。請注意,非零空片和零片(例如,[] byte {}和[] []byte(nil))并不完全相等。

其他值 - 數字,布爾,字符串和通道 - 如果使用Go的==運算符相等,則它們是相等的。

一般而言,DeepEqual 是 Go 的==運算符的遞歸放松。然而,這個想法是不可能實現的,沒有一些不一致。具體而言,一個值可能與自身不相等,或者是因為它是 func 類型(通常無法比較),或者因為它是浮點型 NaN 值(在浮點比較中不等于自身),或者因為它是浮點型它是包含這種值的數組,結構或接口。另一方面,指針值總是等于它們自己,即使它們指向或包含這樣的有問題的值,因為它們使用 Go 的==運算符比較相等,并且這是一個足夠的條件,無論內容如何,它都是完全相等的。DeepEqual 已被定義,以便相同的捷徑適用于切片和貼圖:如果 x 和 y 是相同的切片或相同的貼圖,則無論內容如何,它們都是完全相同的。

當 DeepEqual 遍歷數據值時,它可能會找到一個循環(huán)。第二次和后來的時間,DeepEqual 比較之前比較過的兩個指針值,它將這些值視為相等,而不是檢查它們指向的值。這確保了 DeepEqual 終止。

func Select

func Select(cases []SelectCase) (chosen int, recv Value, recvOK bool)

選擇執(zhí)行由案例列表描述的選擇操作。與 Go select 語句一樣,它會阻塞,直到至少有一種情況可以繼續(xù),進行統(tǒng)一的偽隨機選擇,然后執(zhí)行該情況。它返回所選情況的索引,如果是接收操作,則返回接收到的值,并返回一個布爾值,指示該值是否與通道上的發(fā)送相對應(與通道關閉時接收的零值相對)。

func Swapper

func Swapper(slice interface{}) func(i, j int)

Swapper 返回一個函數,它交換提供的 slice 中的元素。

如果提供的接口不是切片,Swapper 會發(fā)生混亂。

type ChanDir

ChanDir 代表了一種渠道類型的方向。

type ChanDir int
const (
        RecvDir ChanDir             = 1 << iota // <-chan
        SendDir                                 // chan<-
        BothDir = RecvDir | SendDir             // chan)

func (ChanDir) String

func (d ChanDir) String() string

type Kind

類型表示類型代表的特定種類。零種類不是一種有效的種類。

type Kind uint
const (
        Invalid Kind = iota
        Bool
        Int
        Int8
        Int16
        Int32
        Int64
        Uint
        Uint8
        Uint16
        Uint32
        Uint64
        Uintptr
        Float32
        Float64
        Complex64
        Complex128
        Array
        Chan
        Func
        Interface        Map
        Ptr
        Slice
        String
        Struct
        UnsafePointer)

func (Kind) String

func (k Kind) String() string

type Method

Method 代表一種方法。

type Method struct {        // Name is the method name.        // PkgPath is the package path that qualifies a lower case (unexported)        // method name. It is empty for upper case (exported) method names.        // The combination of PkgPath and Name uniquely identifies a method        // in a method set.        // See https://golang.org/ref/spec#Uniqueness_of_identifiers
        Name    string
        PkgPath string

        Type  Type  // method type
        Func  Value // func with receiver as first argument
        Index int   // index for Type.Method}

type SelectCase

SelectCase 在選擇操作中描述了一個案例。這種情況取決于 Dir ,溝通方向。

如果 Dir 是 SelectDefault ,則表示默認情況。Chan 和 Send 必須為零值。

如果 Dir 是 SelectSend ,則表示發(fā)送操作。通常 Chan 的基礎值必須是一個通道,并且 Send 的基礎值必須可分配給通道的元素類型。作為一種特殊情況,如果 Chan 是零值,則忽略該情況,并且發(fā)送字段也將被忽略,并且可以是零或非零。

如果 Dir 是 SelectRecv ,則表示接收操作。通常陳的基礎價值必須是一個渠道和發(fā)送必須是一個零值。如果 Chan 是零值,則該情況將被忽略,但發(fā)送必須仍為零值。當選擇接收操作時,接收的值由選擇返回。

type SelectCase struct {
        Dir  SelectDir // direction of case
        Chan Value     // channel to use (for send or receive)
        Send Value     // value to send (for send)}

type SelectDir

SelectDir 描述選擇案例的通信方向。

type SelectDir int
const (
        SelectSend    SelectDir // case Chan <- Send
        SelectRecv              // case <-Chan:
        SelectDefault           // default)

type SliceHeader

SliceHeader 是切片的運行時表示。它不能被安全地使用或移植,其代表可能會在以后的版本中發(fā)生變化。此外,數據字段不足以保證它所引用的數據不會被垃圾收集,因此程序必須保持一個單獨的,正確類型的指向底層數據的指針。

type SliceHeader struct {
        Data uintptr
        Len  int
        Cap  int}

type StringHeader

StringHeader 是字符串的運行時表示。它不能被安全地使用或移植,其代表可能會在以后的版本中發(fā)生變化。此外,數據字段不足以保證它所引用的數據不會被垃圾收集,因此程序必須保持一個單獨的,正確類型的指向底層數據的指針。

type StringHeader struct {
        Data uintptr
        Len  int}

type StructField

StructField 描述結構中的單個字段。

type StructField struct {        // Name is the field name.
        Name string        // PkgPath is the package path that qualifies a lower case (unexported)        // field name. It is empty for upper case (exported) field names.        // See https://golang.org/ref/spec#Uniqueness_of_identifiers
        PkgPath string

        Type      Type      // field type
        Tag       StructTag // field tag string
        Offset    uintptr   // offset within struct, in bytes
        Index     []int     // index sequence for Type.FieldByIndex
        Anonymous bool      // is an embedded field}

type StructTag

StructTag 是 struct 字段中的標記字符串。

按照慣例,標記字符串是可選空間分隔鍵:“值”對的串聯。每個鍵都是由空格 (U+0020 ' '),引號(U+0022 '"')和冒號(U+003A ':')以外的非控制字符組成的非空字符串。使用U + 0022'“'字符和 Go 字符串文字語法。

type StructTag string

func (StructTag) Get

func (tag StructTag) Get(key string) string

獲取返回與標記字符串中的鍵關聯的值。如果標簽中沒有這樣的密鑰,則 Get 返回空字符串。如果標簽不具有傳統(tǒng)格式,則 Get 返回的值是未指定的。要確定標記是否顯式設置為空字符串,請使用查找。

func (StructTag) Lookup

func (tag StructTag) Lookup(key string) (value string, ok bool)

查找將返回與標記字符串中的鍵關聯的值。如果密鑰存在于標簽中,則返回值(可能為空)。否則,返回的值將是空字符串。ok 返回值報告該值是否在標記字符串中明確設置。如果標記不具有傳統(tǒng)格式,則查找返回的值未指定。

type Type

Type 是 Go 類型的表示。

并非所有方法都適用于各種類型。每種方法的文檔中都會注明限制(如果有的話)。在調用種類特定的方法之前,使用 Kind 方法找出類型的類型。調用不適合這種類型的方法會導致運行時恐慌。

類型值具有可比性,如使用==運算符。如果兩個類型的值表示相同類型,則這兩個值相等

type Type interface {        // Align returns the alignment in bytes of a value of        // this type when allocated in memory.        Align() int        // FieldAlign returns the alignment in bytes of a value of        // this type when used as a field in a struct.        FieldAlign() int        // Method returns the i'th method in the type's method set.        // It panics if i is not in the range [0, NumMethod()).        //        // For a non-interface type T or *T, the returned Method's Type and Func        // fields describe a function whose first argument is the receiver.        //        // For an interface type, the returned Method's Type field gives the        // method signature, without a receiver, and the Func field is nil.        Method(int) Method        // MethodByName returns the method with that name in the type's        // method set and a boolean indicating if the method was found.        //        // For a non-interface type T or *T, the returned Method's Type and Func        // fields describe a function whose first argument is the receiver.        //        // For an interface type, the returned Method's Type field gives the        // method signature, without a receiver, and the Func field is nil.        MethodByName(string) (Method, bool)        // NumMethod returns the number of exported methods in the type's method set.        NumMethod() int        // Name returns the type's name within its package.        // It returns an empty string for unnamed types.        Name() string        // PkgPath returns a named type's package path, that is, the import path        // that uniquely identifies the package, such as "encoding/base64".        // If the type was predeclared (string, error) or unnamed (*T, struct{}, []int),        // the package path will be the empty string.        PkgPath() string        // Size returns the number of bytes needed to store        // a value of the given type; it is analogous to unsafe.Sizeof.        Size() uintptr        // String returns a string representation of the type.        // The string representation may use shortened package names        // (e.g., base64 instead of "encoding/base64") and is not        // guaranteed to be unique among types. To test for type identity,        // compare the Types directly.        String() string        // Kind returns the specific kind of this type.        Kind() Kind        // Implements reports whether the type implements the interface type u.        Implements(u Type) bool        // AssignableTo reports whether a value of the type is assignable to type u.        AssignableTo(u Type) bool        // ConvertibleTo reports whether a value of the type is convertible to type u.        ConvertibleTo(u Type) bool        // Comparable reports whether values of this type are comparable.        Comparable() bool        // Bits returns the size of the type in bits.        // It panics if the type's Kind is not one of the        // sized or unsized Int, Uint, Float, or Complex kinds.        Bits() int        // ChanDir returns a channel type's direction.        // It panics if the type's Kind is not Chan.        ChanDir() ChanDir        // IsVariadic reports whether a function type's final input parameter        // is a "..." parameter. If so, t.In(t.NumIn() - 1) returns the parameter's        // implicit actual type []T.        //        // For concreteness, if t represents func(x int, y ... float64), then        //        //	t.NumIn() == 2        //	t.In(0) is the reflect.Type for "int"        //	t.In(1) is the reflect.Type for "[]float64"        //	t.IsVariadic() == true        //        // IsVariadic panics if the type's Kind is not Func.        IsVariadic() bool        // Elem returns a type's element type.        // It panics if the type's Kind is not Array, Chan, Map, Ptr, or Slice.        Elem() Type        // Field returns a struct type's i'th field.        // It panics if the type's Kind is not Struct.        // It panics if i is not in the range [0, NumField()).        Field(i int) StructField        // FieldByIndex returns the nested field corresponding        // to the index sequence. It is equivalent to calling Field        // successively for each index i.        // It panics if the type's Kind is not Struct.        FieldByIndex(index []int) StructField        // FieldByName returns the struct field with the given name        // and a boolean indicating if the field was found.        FieldByName(name string) (StructField, bool)        // FieldByNameFunc returns the struct field with a name        // that satisfies the match function and a boolean indicating if        // the field was found.        //        // FieldByNameFunc considers the fields in the struct itself        // and then the fields in any anonymous structs, in breadth first order,        // stopping at the shallowest nesting depth containing one or more        // fields satisfying the match function. If multiple fields at that depth        // satisfy the match function, they cancel each other        // and FieldByNameFunc returns no match.        // This behavior mirrors Go's handling of name lookup in        // structs containing anonymous fields.        FieldByNameFunc(match func(string) bool) (StructField, bool)        // In returns the type of a function type's i'th input parameter.        // It panics if the type's Kind is not Func.        // It panics if i is not in the range [0, NumIn()).        In(i int) Type        // Key returns a map type's key type.        // It panics if the type's Kind is not Map.        Key() Type        // Len returns an array type's length.        // It panics if the type's Kind is not Array.        Len() int        // NumField returns a struct type's field count.        // It panics if the type's Kind is not Struct.        NumField() int        // NumIn returns a function type's input parameter count.        // It panics if the type's Kind is not Func.        NumIn() int        // NumOut returns a function type's output parameter count.        // It panics if the type's Kind is not Func.        NumOut() int        // Out returns the type of a function type's i'th output parameter.        // It panics if the type's Kind is not Func.        // It panics if i is not in the range [0, NumOut()).        Out(i int) Type        // contains filtered or unexported methods}

func ArrayOf

func ArrayOf(count int, elem Type) Type

ArrayOf 使用給定的計數和元素類型返回數組類型。例如,如果 t 表示 int ,則 ArrayOf(5, t) 表示 5int 。

如果生成的類型會比可用的地址空間大, ArrayOf 恐慌。

func ChanOf

func ChanOf(dir ChanDir, t Type) Type

ChanOf 返回具有給定方向和元素類型的通道類型。例如,如果 t 表示 int ,則 ChanOf(RecvDir,t) 表示 <-chan int 。

gc 運行時在通道元素類型上施加了 64 kB 的限制。如果t的大小等于或超過此限制, ChanOf 恐慌。

func FuncOf

func FuncOf(in, out []Type, variadic bool) Type

FuncOf 返回給定參數和結果類型的函數類型。例如,如果 k 表示 int 并且 e 表示字符串,則 FuncOf([] Type {k},[] Type {e},false) 表示 func(int) 字符串。

可變參數控制函數是否可變。如果 inlen(in)-1 不代表切片并且可變參數為真,則 FuncOf 發(fā)生混亂。

func MapOf

func MapOf(key, elem Type) Type

MapOf 使用給定的鍵和元素類型返回地圖類型。例如,如果 k 表示 int 并且 e 表示字符串,則 MapOf(k, e) 表示 mapintstring 。

如果鍵類型不是有效的映射鍵類型(也就是說,如果它不執(zhí)行 Go 的==運算符),則 MapOf 發(fā)生混亂。

func PtrTo

func PtrTo(t Type) Type

PtrTo 返回指向元素t的指針類型。例如,如果 t 表示類型 Foo ,則 PtrT(t) 表示 * Foo 。

func SliceOf

func SliceOf(t Type) Type

SliceOf 返回元素類型為 t 的切片類型。例如,如果 t 表示 int , SliceOf(t) 表示 [] int 。

func StructOf

func StructOf(fields []StructField) Type

StructOf 返回包含字段的結構類型。偏移量和索引字段被忽略和計算,就像編譯器一樣。

StructOf 目前不會為嵌入字段生成封裝器方法。未來版本中可能會取消此限制。

func TypeOf

func TypeOf(i interface{}) Type

TypeOf 返回表示i的動態(tài)類型的反射 Type 。如果我是一個無接口值, TypeOf 返回 nil 。

type Value

Value 是 Go 值的反射界面。

并非所有方法都適用于各種價值。每種方法的文檔中都會注明限制(如果有的話)。在調用種類特定的方法之前,使用 Kind 方法找出這種值。調用不適合這種類型的方法會導致運行時間恐慌。

零值表示沒有值。它的 IsValid 方法返回 false ,其 Kind 方法返回Invalid,其 String 方法返回 “<invalid Value>” ,所有其他方法都會出現混亂。大多數函數和方法永遠不會返回無效值。如果有的話,其文件明確說明條件。

一個值可以被多個 goroutine 同時使用,前提是 Go 值可以同時用于等價的直接操作。

要比較兩個值,請比較 Interface 方法的結果。在兩個值上使用==不會比較它們表示的基礎值。

type Value struct {        // contains filtered or unexported fields}

func Append

func Append(s Value, x ...Value) Value

追加將值 x 附加到切片 s 并返回結果切片。和 Go 一樣,每個 x 的值必須可分配給切片的元素類型。

func AppendSlice

func AppendSlice(s, t Value) Value

AppendSlice 將切片 t 附加到切片 s 并返回結果切片。切片 s 和 t 必須具有相同的元素類型。

func Indirect

func Indirect(v Value) Value

間接返回 v 指向的值。如果 v 是一個零指針,則間接返回一個零值。如果 v 不是指針,則間接返回 v 。

func MakeChan

func MakeChan(typ Type, buffer int) Value

MakeChan 使用指定的類型和緩沖區(qū)大小創(chuàng)建一個新的通道。

func MakeFunc

func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value

MakeFunc 返回一個包裝函數 fn 的給定類型的新函數。被調用時,該新功能執(zhí)行以下操作:

- converts its arguments to a slice of Values.- runs results := fn(args).- returns the results as a slice of Values, one per formal result.

實現 fn 可以假定參數 Value slice 具有由 typ 給出的參數的數量和類型。如果 typ 描述了一個可變參數函數,那么最終的值本身就是一個表示可變參數的分片,就像可變參數函數的主體一樣。結果由 fn 返回的值切片必須具有由 typ 給出的結果的數量和類型。

Value.Call 方法允許調用者根據值調用類型化函數; 相比之下, MakeFunc 允許調用者根據值實現類型化函數。

文檔的 Examples 部分包含了如何使用 MakeFunc 為不同類型構建交換函數的說明。

func MakeMap

func MakeMap(typ Type) Value

MakeMap 使用指定的類型創(chuàng)建一個新的地圖。

func MakeMapWithSize

func MakeMapWithSize(typ Type, n int) Value

MakeMapWithSize 為約 n 個元素創(chuàng)建一個具有指定類型和初始空間的新映射。

func MakeSlice

func MakeSlice(typ Type, len, cap int) Value

MakeSlice 為指定的切片類型,長度和容量創(chuàng)建新的零初始化切片值。

func New

func New(typ Type) Value

New 返回一個 Value ,表示指向指定類型的新零值的指針。也就是說,返回值的類型是 PtrTo(typ) 。

func NewAt

func NewAt(typ Type, p unsafe.Pointer) Value

NewAt 返回一個表示指向指定類型值的指針的值,使用 p 作為指針。

func ValueOf

func ValueOf(i interface{}) Value

ValueOf 返回一個新值,初始化為存儲在接口 i 中的具體值。ValueOf(nil) 返回零值。

func Zero

func Zero(typ Type) Value

Zero 返回表示指定類型的零值的值。結果與 Value 結構的零值不同,后者完全不表示任何值。例如, Zero(TypeOf(42)) 返回一個 Value with Kind Int 和值0。返回的值既不可尋址也不可設置。

func (Value) Addr

func (v Value) Addr() Value

Addr 返回一個代表 v 的地址的指針值,如果 CanAddr() 返回 false ,則會發(fā)生混亂。 Addr 通常用于獲取指向結構體字段或切片元素的指針,以便調用需要指針接收器的方法。

func (Value) Bool

func (v Value) Bool() bool

布爾返回 v 的基礎價值。如果 v 的種類不是 Bool ,它會感到恐慌。

func (Value) Bytes

func (v Value) Bytes() []byte

字節(jié)返回 v 的基礎值。如果 v 的基礎值不是一個字節(jié)片段,它會發(fā)生混亂。

func (Value) Call

func (v Value) Call(in []Value) []Value

例如,如果 len(in)== 3,v.Call(in) 表示 Go 調用 v(in0,in1,in2) 。如果 v 的 Kind 不是 Func ,則調用 panics 。它將輸出結果作為值返回。和 Go 一樣,每個輸入參數必須可以分配給函數相應輸入參數的類型。如果 v 是一個可變參數函數, Call 將自己創(chuàng)建可變參數切片參數,并復制相應的值。

func (Value) CallSlice

func (v Value) CallSlice(in []Value) []Value

CallSlice 調用帶有輸入參數的可變參數函數 v ,將片段 inlen(in)-1 分配給 v 的最終可變參數。例如,如果 len(in)== 3 , v.CallSlice(in) 表示 Go 呼叫 v(in0,in1,in2 ...) 。如果 v 的 Kind 不是 Func 或者 v 不是可變參數, CallSlice 會發(fā)生混亂。它將輸出結果作為值返回。和 Go 一樣,每個輸入參數必須可以分配給函數相應輸入參數的類型。

func (Value) CanAddr

func (v Value) CanAddr() bool

CanAddr 報告是否可以使用 Addr 獲取該值的地址。這些值稱為可尋址的。如果值是切片的元素,可尋址數組的元素,可尋址結構的字段或取消引用指針的結果,則該值是可尋址的。如果 CanAddr 返回 false ,調用 Addr 將會發(fā)生混亂。

func (Value) CanInterface

func (v Value) CanInterface() bool

CanInterface 報告 Interface 是否可以在沒有恐慌的情況下使用。

func (Value) CanSet

func (v Value) CanSet() bool

CanSet 報告 v 的值是否可以改變。值只能在可尋址的情況下更改,并且不能通過使用未導出的結構字段獲取。如果 CanSet 返回 false ,則調用 Set 或任何類型特定的 setter (例如 SetBool ,SetInt )將會發(fā)生混亂。

func (Value) Cap

func (v Value) Cap() int

Cap 返回 v 的容量。如果 v 的 Kind 不是 Array,Chan 或 Slice ,它會發(fā)生混亂。

func (Value) Close

func (v Value) Close()

關閉關閉頻道 v 。如果 v 的 Kind 不是 Chan ,它會發(fā)生混亂。

func (Value) Complex

func (v Value) Complex() complex128

綜合體返回 v 的底層價值,作為一個綜合體128。如果 v 的 Kind 不是 Complex64 或 Complex128 ,它會發(fā)生混亂

func (Value) Convert

func (v Value) Convert(t Type) Value

轉換返回轉換為類型 t 的值 v 。如果通常的 Go 轉換規(guī)則不允許將值 v 轉換為類型 t ,則轉換恐慌。

func (Value) Elem

func (v Value) Elem() Value

Elem 返回接口 v 包含的值或指針 v 指向的值。如果 v 的 Kind 不是 Interface 或 Ptr ,它會發(fā)生混亂。如果 v 為零,它返回零值。

func (Value) Field

func (v Value) Field(i int) Value

Field 返回 struct v 的第 i 個字段,如果 v 的 Kind 不是 Struct 或者我超出范圍,它就會發(fā)生混亂。

func (Value) FieldByIndex

func (v Value) FieldByIndex(index []int) Value

FieldByIndex 返回索引對應的嵌套字段。如果 v 的 Kind 不是 struct ,它會發(fā)生混亂。

func (Value) FieldByName

func (v Value) FieldByName(name string) Value

FieldByName 返回給定名稱的 struct 字段。如果沒有找到字段,它將返回零值。如果 v 的 Kind 不是 struct ,它會發(fā)生混亂。

func (Value) FieldByNameFunc

func (v Value) FieldByNameFunc(match func(string) bool) Value

FieldByNameFunc 返回結構字段,其名稱滿足匹配函數。如果 v 的 Kind 不是 struct ,它會發(fā)生混亂。如果沒有找到字段,它將返回零值。

func (Value) Float

func (v Value) Float() float64

Float 返回 v 的基礎值,作為 float64 。如果 v 的 Kind 不是 Float32 或 Float64 ,它會發(fā)生混亂

func (Value) Index

func (v Value) Index(i int) Value

索引返回 v 的第 i 個元素。如果 v 的 Kind 不是 Array,Slice 或 String ,或者我超出范圍,它會發(fā)生混亂。

func (Value) Int

func (v Value) Int() int64

Int 返回 v 的基礎值,如 int64 。如果 v 的 Kind 不是 Int , Int8 , Int16 , Int32 或 Int64 ,則會發(fā)生混亂。

func (Value) Interface

func (v Value) Interface() (i interface{})

接口返回 v 的當前值作為 interface{} 。它相當于:

var i interface{} = (v's underlying value)

如果通過訪問未導出的結構體域來獲取值,它會發(fā)生混亂。

func (Value) InterfaceData

func (v Value) InterfaceData() [2]uintptr

InterfaceData 以 uintptr 對的形式返回接口 v 的值。如果 v 的 Kind 不是 Interface ,它會發(fā)生混亂。

func (Value) IsNil

func (v Value) IsNil() bool

IsNil 報告其參數 v 是否為零。參數必須是 chan , func ,接口,映射,指針或切片值; 如果不是,IsNil 恐慌。請注意,IsNil 并非總是與 Go 中的零比較。例如,如果通過使用未初始化的接口變量 i 調用 ValueOf 來創(chuàng)建 v ,那么 i == nil 將為 true,但 v.IsNil 會因為 v 將是零值而發(fā)生混亂。

func (Value) IsValid

func (v Value) IsValid() bool

IsValid 報告 v 是否表示一個值。如果 v 是零值,它將返回 false 。如果 IsValid 返回 false ,除了 String  panic 之外的所有其他方法。大多數函數和方法永遠不會返回無效值。如果有的話,其文件明確說明條件。

func (Value) Kind

func (v Value) Kind() Kind

Kind返回v的Kind。如果v是零值(IsValid返回false),Kind將返回無效。

func (Value) Len

func (v Value) Len() int

Len 返回 v 的長度。如果 v 的 Kind 不是 Array,Chan,Map,Slice 或 String,它會發(fā)生混亂。

func (Value) MapIndex

func (v Value) MapIndex(key Value) Value

MapIndex 返回地圖 v 中與鍵相關的值。如果 v 的 Kind 不是 Map ,它會發(fā)生混亂。如果在地圖中未找到鍵或者如果 v 表示零映射,它將返回零值。和 Go 一樣,鍵的值必須可以分配給地圖的鍵類型。

func (Value) MapKeys

func (v Value) MapKeys() []Value

MapKeys 以未指定的順序返回包含地圖中所有鍵的切片。如果 v 的 Kind 不是 Map ,它會驚慌失措。如果 v 表示一個零映射,它將返回一個空片段。

func (Value) Method

func (v Value) Method(i int) Value

方法返回對應于 v 的第 i 個方法的函數值。對返回函數調用的參數不應包含接收方; 返回的函數將始終使用v作為接收者。如果我超出范圍或者 v 是一個無界面值,方法會發(fā)生混亂。

func (Value) MethodByName

func (v Value) MethodByName(name string) Value

MethodByName 返回與給定名稱的v的方法對應的函數值。對返回函數調用的參數不應包含接收方; 返回的函數將始終使用 v 作為接收者。如果沒有找到方法,它返回零值。

func (Value) NumField

func (v Value) NumField() int

NumField 返回 struct v 中的字段數。如果 v 的 Kind 不是 Struct ,則會發(fā)生混亂。

func (Value) NumMethod

func (v Value) NumMethod() int

NumMethod 返回值的方法集中導出方法的數量。

func (Value) OverflowComplex

func (v Value) OverflowComplex(x complex128) bool

OverflowComplex 報告 complex128 x 是否不能用 v 的類型表示。如果 v 的 Kind 不是 Complex64 或 Complex128,它會發(fā)生混亂。

func (Value) OverflowFloat

func (v Value) OverflowFloat(x float64) bool

OverflowFloat 報告 float64 x 是否不能由 v 的類型表示。如果 v 的 Kind 不是 Float32 或 Float64 ,它會發(fā)生混亂。

func (Value) OverflowInt

func (v Value) OverflowInt(x int64) bool

OverflowInt 報告 int64 x 是否不能用 v 的類型表示。如果 v 的 Kind 不是 Int,Int8,int16,Int32 或 Int64,它會發(fā)生混亂。

func (Value) OverflowUint

func (v Value) OverflowUint(x uint64) bool

OverflowUint 報告 uint64 x 是否不能用 v 的類型表示。如果 v 的 Kind 不是 Uint,Uintptr,Uint8,Uint16,Uint32 或 Uint64,它會發(fā)生混亂。

func (Value) Pointer

func (v Value) Pointer() uintptr

指針返回 v 的值作為 uintptr 。它返回 uintptr 而不是 unsafe.Pointer,以便使用 reflect 的代碼無法顯式地導入不安全的包而無法獲取不安全的指針。如果 v 的 Kind 不是 Chan,Func,Map,Ptr,Slice 或 UnsafePointer,它會發(fā)生混亂。

如果 v 的 Kind 是 Func,則返回的指針是底層代碼指針,但不一定足以唯一地標識單個函數。唯一的保證是,當且僅當 v 是一個 nil func 值時,結果為零。

如果 v 的種類是切片,返回的指針是切片的第一個元素。如果切片為零,則返回值為0.如果切片為空,但非零,則返回值不為零。

func (Value) Recv

func (v Value) Recv() (x Value, ok bool)

Recv 接收并返回來自頻道 v 的值。如果 v 的 Kind 不是 Chan,它會發(fā)生混亂。接收阻塞,直到值準備就緒。如果值 x 對應于通道上的發(fā)送,則布爾值 ok;如果由于通道已關閉而接收到零值,則返回 false 。

func (Value) Send

func (v Value) Send(x Value)

發(fā)送在通道 v 上發(fā)送 x ,如果 v 的類型不是 Chan,或者 x 的類型與 v 的元素類型不是同一類型,則會發(fā)生混亂。和 Go 一樣,x 的值必須可分配給通道的元素類型。

func (Value) Set

func (v Value) Set(x Value)

將 x 賦值給 v 。如果 CanSet 返回 false,則會發(fā)生混亂。和 Go 一樣, x 的值必須賦值給 v 的類型。

func (Value) SetBool

func (v Value) SetBool(x bool)

SetBool 設置 v 的基礎值。如果 v 的 Kind 不是 Bool 或者 CanSet() 是 false ,它會發(fā)生混亂。

func (Value) SetBytes

func (v Value) SetBytes(x []byte)

SetBytes 設置 v 的基礎值。如果 v 的基礎值不是一個字節(jié)片段,它會發(fā)生混亂。

func (Value) SetCap

func (v Value) SetCap(n int)

SetCap 將 v 的容量設置為 n 。如果 v 的 Kind 不是 Slice,或者 n 小于長度或大于切片的容量,它會發(fā)生混亂。

func (Value) SetComplex

func (v Value) SetComplex(x complex128)

SetComplex 將 v 的基礎值設置為 x 。如果 v 的 Kind 不是 Complex64 或 Complex128 ,或者 CanSet() 為 false ,則會發(fā)生混亂。

func (Value) SetFloat

func (v Value) SetFloat(x float64)

SetFloat 將 v 的基礎值設置為 x 。如果 v 的 Kind 不是 Float32 或 Float64 ,或者 CanSet() 是 false ,它會發(fā)生混亂。

func (Value) SetInt

func (v Value) SetInt(x int64)

SetInt 將 v 的基礎值設置為 x 。如果 v 的 Kind 不是 Int,Int8,Int16,Int32 或 Int64,或者 CanSet() 為 false,它會發(fā)生混亂。

func (Value) SetLen

func (v Value) SetLen(n int)

SetLen 將 v 的長度設置為 n 。如果 v 的 Kind 不是 Slice 或 n 是負值或大于切片的容量,它會發(fā)生混亂。

func (Value) SetMapIndex

func (v Value) SetMapIndex(key, val Value)

SetMapIndex 將與地圖 v 中的鍵關聯的值設置為 val 。如果 v 的 Kind 不是 Map ,它會驚慌失措。如果 val 是零值,則 SetMapIndex 從地圖中刪除鍵。否則,如果 v 擁有一個零映射, SetMapIndex 將會出現混亂。與 Go 中一樣,鍵的值必須可以分配給地圖的鍵類型,并且 val 的值必須可以分配給地圖的值類型。

func (Value) SetPointer

func (v Value) SetPointer(x unsafe.Pointer)

SetPointer 將 unsafe.Pointer 值 v 設置為 x 。如果 v 的 Kind 不是 UnsafePointer ,它會發(fā)生混亂。

func (Value) SetString

func (v Value) SetString(x string)

SetString 將 v 的基礎值設置為 x 。如果 v 的 Kind 不是 String 或者 CanSet() 為 false ,它會發(fā)生混亂。

func (Value) SetUint

func (v Value) SetUint(x uint64)

SetUint 將 v 的基礎值設置為 x 。如果 v 的 Kind 不是 Uint,Uintptr,Uint8,Uint16,Uint32 或 Uint64,或者 CanSet() 為 false,它會發(fā)生混亂。

func (Value) Slice

func (v Value) Slice(i, j int) Value

切片返回 vi:j 。如果 v 的 Kind 不是 Array,Slice 或 String,或者如果 v 是不可尋址的數組,或者索引超出范圍,它會發(fā)生混亂。

func (Value) Slice3

func (v Value) Slice3(i, j, k int) Value

Slice3 是 slice 操作的3索引形式:它返回 vi:j:k 。如果 v 的 Kind 不是 Array 或 Slice ,或者 v 是不可尋址的數組,或者索引超出范圍,它會發(fā)生混亂。

func (Value) String

func (v Value) String() string

字符串以字符串形式返回字符串v的基礎值。由于 Go 的 String 方法約定,字符串是一種特殊情況。與其他 getter 不同,如果 v 的 Kind 不是 String,它不會驚慌。相反,它返回一個形式為“<T value>”的字符串,其中 T 是 v 的類型。fmt 包專門處理值。它不隱式地調用它們的 String 方法,而是打印它們保存的具體值。

func (Value) TryRecv

func (v Value) TryRecv() (x Value, ok bool)

TryRecv 嘗試從通道 v 接收一個值,但不會阻塞。如果 v 的 Kind 不是 Chan ,它會驚慌失措。如果接收提供了一個值,x 是傳輸值,ok 是真實的。如果接收不能沒有阻塞地完成,則 x 是零值并且 ok 是假的。如果通道關閉,x 是通道元素類型的零值,ok 是假。

func (Value) TrySend

func (v Value) TrySend(x Value) bool

TrySend 嘗試在通道 v 上發(fā)送 x,但不會阻止。如果 v 的 Kind 不是 Chan ,它會驚慌失措。它報告是否發(fā)送了該值。和 Go 一樣, x 的值必須可分配給通道的元素類型。

func (Value) Type

func (v Value) Type() Type

類型返回 v 的類型。

func (Value) Uint

func (v Value) Uint() uint64

Uint 返回 v 的基礎值,作為 uint64 。如果 v 的 Kind 不是 Uint,Uintptr,Uint8,Uint16,Uint32 或 Uint64,它會發(fā)生混亂。

func (Value) UnsafeAddr

func (v Value) UnsafeAddr() uintptr

UnsafeAddr 返回一個指向 v 數據的指針。對于那些也導入“不安全”軟件包的高級客戶來說。如果 v 不可尋址,它會發(fā)生混亂。

type ValueError

如果在不支持 Value 的 Value 上調用 Value 方法,則會發(fā)生 ValueError 。這些情況記錄在每種方法的描述中。

type ValueError struct {
        Method string
        Kind   Kind}

func (*ValueError) Error

func (e *ValueError) Error() string

Bugs

  • ?   如果名字相同,FieldByName 和相關函數認為結構字段名稱是相等的,即使它們是源自不同包中的未導出名稱。這樣做的實際效果是,如果結構類型t包含多個名為x的字段(從不同的包中嵌入),則 t.FieldByName(“x”) 的結果沒有很好地定義。FieldByName 可能會返回其中一個名為x的字段,或者可能會報告沒有字段。有關更多詳細信息,請參閱 golang.org/issue/4876 。

上一篇: 下一篇: