I have a some structs,
type Fruit struct {
Name string
Sweetness int
}
type Meat struct {
Name string
Bloodiness int
}
Somtimes a person may eat some fruit, sometimes some meat. So we have another struct.
type Person struct {
Name string
Mealtype interface{}
}
It's this 'Mealtype' interface{} bit I kind of made up to fix my issue.
Go is allowing me to set either a Mealtype to be a Meat or Fruit struct, however. I can't seem to access any of the internal data from the struct.
The fmt.Println( someperson.Mealtype ) doesn't offer my to access either .Bloodiness or .Sweetness
For example, if i do:
f := Fruit{}
f.Name = "Orange"
f.Sweetness = 10
p := Person{}
p.Name = "John"
p.Mealtype = f
fmt.Println(p.Mealtype.Name)
I get the error:
p.Mealtype.Name undefined (type interface{} has no field or method Name)