In most of the function declarations I've seen in Go, the format is Name, Arguments, Output. Such as the following:
func add(a, b int) int {
return a + b
}
But in this example, the pointer is given in the beginning of the declaration, instead of in the argument section right after the name. My question is: what is the cause is this format? Are pointers written differently when they're arguments?
func (p *Page) save() error {
filename := p.Title + ".txt"
return ioutil.WriteFile(filename, p.Body, 0600)
}
in go
there are no classes in the way you usually see them .. instead we use the syntax in question do declare methods on types, the argument in front is called areceiver
and if we use a pointer receiver
we get reference
type semantics otherwise you get value
type semantics. check out the go
tour it is awesome.