You can't modify or extend an already declared interface, you can only create a new one, possibly extending the old one. But you cannot re-declare methods in the interface.
This means that what you want to do (modify the Scribe
interface so that its Log
method has a different signature) is not possible.
What you can do is to have a type which holds your channel and embeds the structure you want to extend.
Example:
type Scribe interface {
Log(Messages []*LogEntry) (ResultCode, error)
}
type ModifiedScribe struct {
Scribe
counts chan string
}
func (m *ModifiedScribe) Log(Messages []*LogEntry) (ResultCode, error) {
// do something with m.counts
// call embedded implementation's Log message
return m.Scribe.Log(Messages)
}
The example above defines a struct which embeds a Scribe
and defines its own Log
method,
utilizing the one of the embedded Scribe
. This struct can be used wherever a Scribe
is expected (as it implements the Scribe
interface) but holds your additional channel.