API
example:
package main
import (
"fmt"
"reflect"
)
type B struct {
}
func main() {
a := "123"
fmt.Println(reflect.TypeOf(a)) //string
var b B
fmt.Println(reflect.TypeOf(b)) //main.B
}
为什么要检测变量类型?
- 前端传过来的数据,比如说bool,int你不知道会转化成什么类型
- 使用别人的库,你也不知道实例是什么类型