I recently write a program to recursively print all fields and value in a struct.
Interface() is the most convinence way to get underlying value in go.But it will panic when field is private.How can I access private field?
For simple type, I can stil use Int(),Bool(),etc to read private field. But if the field is a interface, I do not know how to access is concrete value without use Interface() method.
For example:
type Expr interface {
eval(v string) bool
}
type MyExpr struct {
Haha string
}
type Web struct {
Host string
epr Expr
}
How can I get Web.Epr Value by reflection without use Interface() method