I am trying to write a method on a struct that takes in a interface type and returns that interface type but converted to the appropriate type.
type Model interface {
GetEntity()
}
type TrueFalseQuestions struct {
//some stuff
}
func (q *TrueFalseQuestions) GetEntity() {
//some stuff
}
type MultiQuestions struct {
//some stuff
}
func (q *MultiQuestions) GetEntity() {
//some stuff
}
type Manager struct {
}
func (man *Manager) GetModel(mod Model) Model {
mod.GetEntity()
return mod
}
func main() {
var man Manager
q := TrueFalseQuestions {}
q = man.GetModel(&TrueFalseQuestions {})
}
So when I call GetModel()
with type TrueFalseQuestions
I want to automatically return a TrueFalseQuestions
type. I figured that would mean that my GetModel()
method should return a Model
type. That way if I pass a MultiQuestion
type a MultiQuestion
struct is returned.