Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Created March 2, 2014 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolaveric/9303031 to your computer and use it in GitHub Desktop.
Save rolaveric/9303031 to your computer and use it in GitHub Desktop.
Example of implicit interface implementations in Go
// A Doer is anything that will Do something
type Doer interface {
Do()
}
// X needs a Doer
func X(doer Doer) {
doer.Do()
}
// Y will Do something, and is therefore a Doer
type Y string
func (y Y) Do() {
// Does something
}
func main() {
var y Y = "meep"
X(y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment