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.

In more detail

Use one when a method modifies state, as Add does with c.Value++, or when the struct is large. On an addressable variable Go takes the address for you, so c.Add() works without writing &c.

Example

func (c *Counter) Add() {
	c.Value++
}

Related terms

Taught in

References