method receiver
The special first parameter of a Go method, written before the method name, that is the value the method is called on.
In more detail
In func (t Target) Address(), t is the receiver. A value receiver works on a copy, so it suits read-only methods; a pointer receiver works on the original. Keep one style per type so its method set stays predictable.
Example
func (t Target) Address() stringRelated terms
- method — A function that belongs to an object or type and is called on a value of it, as in name.upper().
- pointer receiver — A method receiver declared as a pointer, such as (c *Counter), which lets the method change the original value rather than a copy.
Taught in
- Structs and Methods — Concurrent Systems Programming with Go
- Channels and Synchronization — Concurrent Systems Programming with Go