Say I have 3 structs:
type A struct{
Foo map[string]string
}
type B struct{
Foo map[string]string
}
type C struct{
Foo map[string]string
}
and then I want to create a function that can accept any of those structs:
func handleFoo (){
}
Is there any way to do this with Golang? Something like:
type ABC = A | B | C
func handleFoo(v ABC){
x: = v.Foo["barbie"] // this would be nice!
}
OK, so let's try an interface:
type FML interface {
Bar() string
}
func handleFoo(v FML){
z := v.Bar() // this will compile
x: = v.Foo["barbie"] // this won't compile - can't access properties like Foo from v
}
In a language which encourages/forces composition, I cannot understand why you can't access properties like Foo.