I would like to manipulate structs at Runtime.
For example, I have a struct:
type Item struct {
SomeField string
}
Is it possible to add field on runtime? Or Access Attribute that is not yet defined. Something like pythons __getattr__() or __call__() so I could dynamically control the fields/methods accessed.
E.g. do something like
Item.DynamicField or Item.DynamicMethod() where I don't know exactly the Field or the Method that will be accessed/called, So I can't define it statically.
Maybe I'm missing something in the Reflect package?
Thank you.
reflectpackage can be used to get exported attributes. I don't know of an equivalent to the call method in Go, but I don't think you it is essential: just create an anonymous function that includes a ref to the object and pass that function instead of the object.