mardi 24 août 2021

Using Reflection on golang, how can I access the properties of the parent struct [duplicate]

Using reflect, I'm trying to access the fields of a Parent struct from within a function implemented on the "Base" struct, like this:

type Base struct {
  X int
}

type Extra struct {
  Base
  Y int
  Z int
}

func (b *Base) Hitme() {
  // Want to access the list of "Extra" fields here
}

The b value only allows me to access the "X" value, not "Y" or "Z".

Here's a compilable example on playground: https://play.golang.org/p/fX0bX_x7FzC





Aucun commentaire:

Enregistrer un commentaire