```
package main
import (
"fmt"
"reflect"
)
type Test struct {
}
func main() {
test1 := new(Test)
test2 := Test{}
t1 := reflect.TypeOf(test1)
t2 := reflect.TypeOf(test2)
fmt.Printf("%t\n", isStruct(t1))
fmt.Printf("%t\n", isStructPtr(t1))
fmt.Printf("%t\n", isStruct(t2))
fmt.Printf("%t\n", isStructPtr(t2))
}
func isStruct(t reflect.Type) bool {
return t.Kind() == reflect.Struct
}
func isStructPtr(t reflect.Type) bool {
return t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct
}
```
有疑问加站长微信联系(非本文作者)