Go interfaces cannot return structs directly because an interface is a type, not a value; instead, define a function that returns the interface type and assign a struct value to it.
type MyInterface interface {
DoSomething()
}
type MyStruct struct{}
func (m MyStruct) DoSomething() {}
func GetInterface() MyInterface {
return MyStruct{}
}
The function GetInterface returns the interface type MyInterface, which holds the concrete MyStruct value.