Skip to content

Instantly share code, notes, and snippets.

@aoeu
Last active August 29, 2015 14:18
Show Gist options
  • Save aoeu/8bc8d8db81f95f7650e9 to your computer and use it in GitHub Desktop.
Save aoeu/8bc8d8db81f95f7650e9 to your computer and use it in GitHub Desktop.
oozer
// https://play.golang.org/p/5rQ7LgR3Wl
package main
import (
"fmt"
"time"
)
type oozer interface{
ooze() string
}
type octopus struct {
numTentacles int
}
func (o octopus) ooze() string {
return "ink"
}
type slug struct {
salted bool
}
func (s slug) ooze() string {
return "slime"
}
func main() {
sammy := slug{salted: false}
ringo := octopus{numTentacles: 8}
oozyThings := make(chan oozer)
go func() {
for {
oozyThing := <-oozyThings
fmt.Println(oozyThing.ooze())
switch oozyThing.(type) {
case slug:
fmt.Println("Salty? ", oozyThing.(slug).salted)
}
}
}()
oozyThings <- sammy
oozyThings <- ringo
<-time.After(1 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment