github.com/brownsys/tracing-framework-go@v0.0.0-20161210174012-0542a62412fe/go/darwin_amd64/misc/tour/content/methods/indirection-values.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "math" 8 ) 9 10 type Vertex struct { 11 X, Y float64 12 } 13 14 func (v Vertex) Abs() float64 { 15 return math.Sqrt(v.X*v.X + v.Y*v.Y) 16 } 17 18 func AbsFunc(v Vertex) float64 { 19 return math.Sqrt(v.X*v.X + v.Y*v.Y) 20 } 21 22 func main() { 23 v := Vertex{3, 4} 24 fmt.Println(v.Abs()) 25 fmt.Println(AbsFunc(v)) 26 27 p := &Vertex{4, 3} 28 fmt.Println(p.Abs()) 29 fmt.Println(AbsFunc(*p)) 30 }