method in Go

Go does not have classes. However, you can define methods on types. In Go, a method is a function with a special receiver argument.The receiver appears in its own argument list between the func keyword and the method name. 
```
func (v Vertex) Abs() float64 {
	return math.Sqrt(v.X*v.X + v.Y*v.Y)
}
```
You can declare a method on non-struct types, too. You can only declare a method with a receiver whose type is defined in the same package as the method. You cannot declare a method with a receiver whose type is defined in another package (which includes the built-in types such as int). 
```
type MyFloat float64

func (f MyFloat) Abs() float64 {
	if f < 0 {
		return float64(-f)
	}
	return float64(f)
}
```
You can declare methods with pointer receivers. This means the receiver type has the literal syntax *T for some type T. (Also, T cannot itself be a pointer such as *int.)
Methods with pointer receivers can modify the value to which the receiver points. Since methods often need to modify their receiver, pointer receivers are more common than value receivers.
Methods with pointer receivers take either a value or a pointer as the receiver when they are called.
Methods with value receivers take either a value or a pointer as the receiver when they are called.
```
package main

type Vertex struct {
	X, Y float64
}

func (v *Vertex) PScale(f float64) {
	v.X = v.X * f
	v.Y = v.Y * f
}

func (v Vertex) Scale(f float64) {
	v.X = v.X * f
	v.Y = v.Y * f
}

func main() {
	v := Vertex{3, 4}
	v.PScale(2)
	v.Scale(2)
	p := &Vertex{4, 3}
	p.Scale(3)
	p.PScale(3)
}
```
Methods with value receivers or pointer receivers take either a value or a pointer as the receiver when they are called.
There are two reasons to use a pointer receiver.
* The first is so that the method can modify the value that its receiver points to.
* The second is to avoid copying the value on each method call. This can be more efficient if the receiver is a large struct, for example.