Created
September 16, 2014 20:17
-
-
Save pricees/4eaa7283ae97bf6a3d92 to your computer and use it in GitHub Desktop.
Go map of interfaces & fun method names
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
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