I'm trying to implement a factory function that will return an instance of one of many structs that fulfil the contract of an interface X
.
m := make(map[string] ?)
func init () {
m["a"] = ?
m["b"] = ?
}
type X interface {
y()
}
type A struct {}
func (a * A) y () {}
type B struct {}
func (b * B) y () {}
function factory(name string) X {
return &m[name]{}
}
The code above is just a simplified demonstration of what I'm trying to achieve - looking for pointers for whether this is possible, or if there is a different go idiom to solve this kind of requirement that I'm missing.