newc
newc copied to clipboard
let return value's type to be an interface
Like the struct myDoer below:
type Doer interface {
Do() (int, error)
}
type myDoer struct {
v int
}
func (r *myDoer) Do() (int, error) {
// ...
return 0, nil
}
And myReader's constructor sig shall be like:
func NewMyDoer(v int) Doer
instead of
func NewMyDoer(v int) *myDoer
It can be an option, and user can choose its constructor to return an pointer or an designated interface.
An interesting idea. But I'm not sure if it's feasible, because I think it would be difficult to identify at the syntax tree level which structs implement which interfaces. Does anyone else have any thoughts on implementation?
An interesting idea. But I'm not sure if it's feasible, because I think it would be difficult to identify at the syntax tree level which structs implement which interfaces. Does anyone else have any thoughts on implementation?
"I also really need this feature because I want to use it with Wire. I think it would be great to add a parameter to specify the interface to bind, just like Wire does, for example: newc -i=Doer."