Last active
August 29, 2015 14:18
-
-
Save aoeu/8bc8d8db81f95f7650e9 to your computer and use it in GitHub Desktop.
oozer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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