liveBook · Manning

Pointer receiver

A pointer receiver is a method receiver whose parameter is a pointer to a value, allowing the method to access or modify that value.

How 2 Manning books explain it

100 Go Mistakes and How to Avoid Them

A pointer receiver is a Go method receiver declared as a pointer, so the method can observe or modify the value referenced by that pointer.

How it is used
Guides method receiver choice when mutation, copying, object size, or later observation of state matters.
How deep it goes
Explains copied pointers, mutation, nil receivers, and deferred receiver evaluation; defers thorough values-versus-pointers performance treatment.
Examples
Contrasts balance updates of 100 versus 150, a nil pointer returned as an error, and deferred prints of `foo` versus `bar`.
What you can do after
Diagnose/debug with it when a method fails to mutate its receiver or a deferred call observes an unexpected value.

Read how 100 Go Mistakes and How to Avoid Them explains pointer receiver →

Learn Go with Pocket-Sized Projects

A pointer receiver is a method receiver whose parameter points to the receiver value, allowing method operations to access the original value.

How it is used
Attaches behavior to a struct while allowing method operations to work through the original value.
How deep it goes
Defines receiver syntax, demonstrates invocation, and gives consistency guidance without detailing method-set internals.
Examples
Uses a terminal word game’s `Game.Play` method and a currency converter’s `Decimal.String` implementation.
What you can do after
Build it from scratch by declaring pointer-receiver methods and calling them on constructor-returned pointers.

Read how Learn Go with Pocket-Sized Projects explains pointer receiver →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.