I have two interfaces:
type Request interface {
Version() string
Method() string
Params() interface{}
Id() interface{}
}
type Responder interface {
NewSuccessResponse() Response
NewErrorResponse() Response
}
I would like to make a RequestResponder interface which combines both of these. Is this possible, or do I have to create a third interface with all 6 functions?
Interface embedding is allowed, as documented in the spec:
An interface
Tmay use a (possibly qualified) interface type nameEin place of a method specification. This is called embedding interfaceEinT; it adds all (exported and non-exported) methods ofEto the interfaceT.
This is done throughout Go's standard library (one example is io.ReadCloser).
In your question, RequestResponder would be constructed as:
type RequestResponder interface {
Request
Responder
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With