Go类型断言

func TypeAssertion(arg ...interface{}){
    for _,v := range arg{
        switch reflect.TypeOf(v).Kind() {
        case reflect.String:
            fmt.Printf("arg %v type of string\n",v)
        case reflect.Int64:
            fmt.Printf("arg %v type of Int64\n",v)
        case reflect.Int32:
            fmt.Printf("arg %v type of Int32\n",v)
        case reflect.Int16:
            fmt.Printf("arg %v type of Int16\n",v)
        case reflect.Int8:
            fmt.Printf("arg %v type of Int8\n",v)
        case reflect.Int:
            fmt.Printf("arg %v type of Int\n",v)
        case reflect.Uint64:
            fmt.Printf("arg %v type of Uint64\n",v)
        case reflect.Uint32:
            fmt.Printf("arg %v type of Uint32\n",v)
        case reflect.Uint16:
            fmt.Printf("arg %v type of Uint16\n",v)
        case reflect.Uint8:
            fmt.Printf("arg %v type of Uint8\n",v)
        case reflect.Uint:
            fmt.Printf("arg %v type of Uint\n",v)
        case reflect.Bool:
            fmt.Printf("arg %v type of Bool\n",v)
        case reflect.Float64:
            fmt.Printf("arg %v type of Float64\n",v)
        case reflect.Float32:
            fmt.Printf("arg %v type of Float64\n",v)
        case reflect.Slice:
            fmt.Printf("arg %v type of Slice\n",v)
        case reflect.Map:
            fmt.Printf("arg %v type of Map\n",v)
        case reflect.Struct:
            fmt.Printf("arg %v type of Struct\n",v)
        case reflect.Chan:
            fmt.Printf("arg %v type of Chan\n",v)
        case reflect.Array:
            fmt.Printf("arg %v type of Array\n",v)
        case reflect.Func:
            fmt.Printf("arg %v type of Func\n",v)
        case reflect.Interface:
            fmt.Printf("arg %v type of Interface\n",v)
        case reflect.Complex64:
            fmt.Printf("arg %v type of Complex64\n",v)
        case reflect.Complex128:
            fmt.Printf("arg %v type of Complex128\n",v)
        case reflect.UnsafePointer:
            fmt.Printf("arg %v type of UnsafePointer\n",v)
        default:
            fmt.Printf("arg %v type of Unknow\n",v)
        }
    }
}

你可能感兴趣的:(Go类型断言)