Method Receivers

This lesson explains with examples method receivers in Go

We'll cover the following

Methods can be associated with a named type (User for instance) or a pointer to a named type (*User). In the two type aliasing examples in previous lesson, methods were defined on the value types (MyStr and MyFloat).

Example

There are two reasons to use a pointer receiver. First, to avoid copying the value on each method call (more efficient if the value type is a large struct). The previous User example would have been better written as follows:

Get hands-on with 1200+ tech skills courses.