本文整理匯總了Golang中reflect.Value.InterfaceData方法的典型用法代碼示例。如果您正苦於以下問題:Golang Value.InterfaceData方法的具體用法?Golang Value.InterfaceData怎麽用?Golang Value.InterfaceData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類reflect.Value
的用法示例。
在下文中一共展示了Value.InterfaceData方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: snapvalue
func snapvalue(w io.Writer, v reflect.Value) {
var q string
switch v.Kind() {
case reflect.Bool: // Not addressable
q = strconv.FormatBool(v.Bool())
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
q = strconv.FormatInt(v.Int(), 36)
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
q = strconv.FormatUint(v.Uint(), 36)
case reflect.Uintptr:
panic("n/s")
case reflect.Float32, reflect.Float64:
q = strconv.FormatFloat(v.Float(), 'g', 65, 64)
case reflect.Complex64, reflect.Complex128:
c := v.Complex()
q = "(" + strconv.FormatFloat(real(c), 'g', 65, 64) + ", " + strconv.FormatFloat(imag(c), 'g', 65, 64) + "i)"
case reflect.Chan, reflect.Func, reflect.Map, reflect.Ptr, reflect.Slice, reflect.UnsafePointer: // Addressable
q = strconv.FormatUint(uint64(v.Pointer()), 36) // uintptr
case reflect.Interface:
d := v.InterfaceData() // [2]uintptr
q = "<" + strconv.FormatUint(uint64(d[0]), 36) + "," + strconv.FormatUint(uint64(d[1]), 36) + ">"
case reflect.String:
q = v.String()
case reflect.Array:
w.Write([]byte("{"))
for i := 0; i < v.Len(); i++ {
snapvalue(w, v.Index(i))
w.Write([]byte(","))
}
w.Write([]byte("}"))
return
case reflect.Struct:
w.Write([]byte("{"))
for i := 0; i < v.NumField(); i++ {
snapvalue(w, v.FieldByIndex([]int{i}))
w.Write([]byte(","))
}
w.Write([]byte("}"))
default:
panic("u")
}
w.Write([]byte(q))
}