The receiver is only a special case of the parameter. Go provides syntactic sugar to attach methods to types by declaring the first parameter as a receiver.
For instance:
func (p *Page) save() error
reads "attach a method called save , which returns error in type *Page ", and does not declare:
func save(p *Page) error
which will read "declare a function called save that takes one parameter of type *Page and returns error "
As proof that this is only syntactic sugar, you can try the following code:
p := new(Page) p.save() (*Page).save(p)
Both last lines represent exactly the same method call.
Also read this answer .
source share