Skip to content

Instantly share code, notes, and snippets.

@dcolish
Created April 30, 2012 15:20
Show Gist options
  • Select an option

  • Save dcolish/2559192 to your computer and use it in GitHub Desktop.

Select an option

Save dcolish/2559192 to your computer and use it in GitHub Desktop.
Interfaces are fun
// A test of the interface types and how they may be passed
package main
import "fmt"
type A interface {
Action()
}
type C interface {
A
isOk() (bool)
}
type B struct {
okness bool
}
func (* B) Action() {
fmt.Println("HELLO")
}
func (p *B) isOk() (bool) {
return p.okness
}
func callToAction (p C) {
p.Action()
}
func main () {
b := B{false}
if b.isOk() {
callToAction(&b)
} else {
println("This is not ok")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment