Skip to content

Instantly share code, notes, and snippets.

@iansmith
Created March 4, 2020 01:44
Show Gist options
  • Save iansmith/62f8c52c81b2a86b2710d59953f66dbe to your computer and use it in GitHub Desktop.
Save iansmith/62f8c52c81b2a86b2710d59953f66dbe to your computer and use it in GitHub Desktop.
package main
import "somedwarf"
import "fmt"
type Sleepy struct {}
type IsHappy interface {
Happy() bool
}
func (s Sleepy) Happy() bool {
return true
}
func main() {
g:=somedwarf.Grumpy{}
s:=Sleepy{}
PrintHappy(g)
PrintHappy(s)
}
func PrintHappy(h IsHappy) {
if h.Happy() {
fmt.Printf("dwarf is happy\n")
} else {
fmt.Printf("dwarf is sad\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment