资源说明:Fill specific types with generic data in Go
This package exports one function, Fit. It takes an arbitrary value and a pointer, then tries to fit the value into the pointer as best it can. type T struct { I int S string T *T } var t T Fit([]interface{}{int64(1), []byte("foo"), nil}, &t) fmt.Println(t) or var n int Fit(int64(1), &n) fmt.Println(n) Currently, Fit can only deal with a handful of input types: int64, uint64, []byte, nil, and []interface{}. It should be expanded to handle any type. It fits slices into structs by recursively fitting each element of the slice to each field in the struct. Fit returns an os.Error if it cannot get the data into the slot, for instance, if the types are incompatible, if a numeric value overflows the slot's type, or if the slot holds a fixed number of elements (i.e. it is an array or a struct) and the input slice does not have the same number of elements.
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。