type Role int
type User struct {
Id int64
Name string
Role Role
}
func ListFields(a interface{}) {
v := reflect.ValueOf(a).Elem()
for j := 0; j < v.NumField(); j++ {
f := v.Field(j)
n := v.Type().Field(j).Name
t := f.Type().String()
fmt.Printf("Name: %s Kind: %s Type: %s
", n, f.Kind(), t)
}
}
func main() {
var u User
ListFields(&u)
}
go run main.go
Name: Id Kind: int64 Type: int64
Name: Name Kind: string Type: string
Name: Role Kind: int Type: main.Role <--- how to get int type ?