Given pseudo go code below:
type(
MyStruct struct {
AFunction func(string) ([]byte, error)
}
MyInterface interface {
AFunction(string) ([]byte, error)
}
)
func NeedThis(s string) ([]byte, error){
//relevant function stuff
}
m := &MyStruct{AFunction: NeedThis}
The problem arises that m does not satisfy the MyInterface interface; and I can somewhat see why this would be so. Is there a way to attach functions to a struct in such a way that the constructed struct satisfies an interface without actually building out defining methods on the struct? I'm having some shadowy/faulty reasoning around this, maybe help to clarify this for me or show a better way to reason through this situation.