github.com/brownsys/tracing-framework-go@v0.0.0-20161210174012-0542a62412fe/go/darwin_amd64/misc/tour/content/methods/interface-values.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "math" 8 ) 9 10 type I interface { 11 M() 12 } 13 14 type T struct { 15 S string 16 } 17 18 func (t *T) M() { 19 fmt.Println(t.S) 20 } 21 22 type F float64 23 24 func (f F) M() { 25 fmt.Println(f) 26 } 27 28 func main() { 29 var i I 30 31 i = &T{"Hello"} 32 describe(i) 33 i.M() 34 35 i = F(math.Pi) 36 describe(i) 37 i.M() 38 } 39 40 func describe(i I) { 41 fmt.Printf("(%v, %T)\n", i, i) 42 }