liveBook · Manning

Value receiver

A value receiver is a method receiver declared as a non-pointer value, causing the method to operate on a copy of the receiver.

How 3 Manning books explain it

100 Go Mistakes and How to Avoid Them

A value receiver is a Go method receiver declared as a value, so the method operates on a copy of the receiver value.

How it is used
Distinguishes value and pointer receivers when choosing how a Go method should operate on its receiver.
How deep it goes
Explains copying, mutation, deferred evaluation, and mutex hazards with examples, while deferring a thorough performance discussion.
Examples
Uses customer balances, deferred printing, and a concurrent counter to expose effects of receiver copies.
What you can do after
Diagnose receiver-copy bugs and choose between value and pointer receivers.

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

Learn Go with Pocket-Sized Projects

A value receiver is a method receiver passed as a value, so invoking the method operates on a copy of the receiver.

How it is used
Guides receiver selection when defining methods on Go structures.
How deep it goes
Explains copying, structure size, consistency, and pointer-field concerns, but defers detailed pointer-field behavior.
Examples
Uses the Game type, its mutable state, and its output pointer field to motivate pointer receivers instead.
What you can do after
Apply via Go by selecting value receivers for small structures and pointer receivers when mutation or pointer fields make copying unsuitable.

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

Go in Action, Second Edition

A value receiver is a method receiver that operates on a copied value of its receiver type rather than on a pointer to that value.

How it is used
Uses value receivers for conversion methods that return new Measurement values while implementing a shared interface.
How deep it goes
Explains the design rationale and shows conversion implementations, but does not develop broader receiver or pointer semantics.
Examples
Demonstrates value receivers through metric and imperial weight and volume conversion methods.
What you can do after
Build conversion methods that return new values and satisfy a focused Convertible interface.

Read how Go in Action, Second Edition explains value receiver →

Also covered in

Related concepts

Questions about value receiver

What is value receiver?

A value receiver is a method receiver declared as a non-pointer value, causing the method to operate on a copy of the receiver.

Which Manning books explain value receiver?

100 Go Mistakes and How to Avoid Them, Learn Go with Pocket-Sized Projects and Go in Action, Second Edition.

What is the difference between value receiver and pointer receiver?

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

What is value receiver a kind of?

Value 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.