跳到内容
观澜涉川 · 札记EN

Go语言中的反射应用:检查类型

· 约 1 分钟阅读

本文介绍一种判断变量类型的方法。

比如,判断是否为切片:

func IsSlice(v interface{}) bool {
return reflect.TypeOf(v).Kind() == reflect.Slice
}