I have a struct like this :
type Parent struct {
example string
}
func (p *Parent) GetMyAttr() {
typ := reflect.TypeOf(p).Elem()
for i := 0; i < typ.NumField(); i++ {
p := typ.Field(i)
if !p.Anonymous {
fmt.Println(p.Name, ":", p.Type)
}
}
}
And if I have another struct like this :
type Child struct {
Parent
another string
}
call GetTypeOfMe() in child like this
ch := Child{Parent{"example"},"another"}
ch.GetMyAttr()
is always return example : string
.
Is this possible to get Child struct in Parent struct with reflection?
Full code is here http://play.golang.org/p/ej4Xh_V2J1
Thanks.