I have an interface like this:
type ViewInterface interface{
Init() View
}
type View struct{
Width int
Height int
}
So I create a new type from View
type MainView View
func (m MainView) Init() MainView{
return MainView{
Width:10,
Height:10,
}
}
then I pass the MainView to the following method:
func Render(views ...ViewInterface){
for _, view := range views {
v := view.Init()
}
}
func main() {
Render(MainView{})
}
But I get this error:
cannot use MainView literal (type MainView) as type ViewInterface in argument to Render: MainView does not implement ViewInterface (wrong type for Init method)
have Init() MainView
want Init() View
Why MianView
is not same as View
? what is the right way to solve this problem?
thanks