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 receiver selection and diagnoses mutation, deferred-call, and nil-interface surprises.
How deep it goes
Explains receiver copying and observable effects with examples, while deferring detailed pointer performance analysis.
Examples
Uses customer balance updates, slice appending, a nil error pointer, and a deferred print method.
What you can do after
Diagnose unexpected receiver mutations and non-nil error interfaces, and choose a receiver based on mutation and copying constraints.

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 →

Also covered in

Related concepts

Questions about pointer receiver

What is 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.

Which Manning books explain pointer receiver?

100 Go Mistakes and How to Avoid Them and Learn Go with Pocket-Sized Projects.

What is the difference between pointer receiver and value 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. A value receiver is a method receiver declared as a non-pointer value, causing the method to operate on a copy of the receiver.

What is pointer receiver a kind of?

Pointer receiver is a kind of receiver. A receiver is an entity or value designated to accept a message, signal, or operation.

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.