Please explain the below syntax, I found this below snippet from godoc. I understand Cookie
is function name and name
is its argument and return type are (*Cookie, error)
, the part I could not understand is (r *Request)
, What exactly this part signifies. By the way I am from OOP background.
func (r *Request) Cookie(name string) (*Cookie, error)
It is called a receiver.
Basically if a function has something before it's name (the receiver) it is now called a method. It's a good way to take structs as arguments.
I would recommend going over https://tour.golang.org/methods/1 for more information.
https://gobyexample.com/methods is also sweet