Skip to content

Instantly share code, notes, and snippets.

@pricees
Created September 16, 2014 20:17
Show Gist options
  • Save pricees/4eaa7283ae97bf6a3d92 to your computer and use it in GitHub Desktop.
Save pricees/4eaa7283ae97bf6a3d92 to your computer and use it in GitHub Desktop.
Go map of interfaces & fun method names
package main
import "fmt"
type Fooable interface {
foo() string
}
type Bar struct { }
func (b *Bar) foo() string {
return "This is Bar#foo"
}
type Baz struct { }
func (b *Baz) foo() string {
return "This is Baz#foo"
}
func 白鵬翔(f Fooable) {
fmt.Println(f.foo())
}
func main() {
var bar, baz Fooable
bar = &Bar{}
baz = &Baz{}
flexers := map[string]Fooable{"bar": bar, "baz": baz}
for k, flexer := range flexers {
fmt.Println("\n=== ", k)
白鵬翔(flexer)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment