Golang Method Receivers in 5 Minutes
Go method receivers for beginners, in five minutes, on a real Go program: why a method with a value receiver changes only a copy, the one-star fix with a pointer receiver, why Go takes the address for you, the Go FAQ's rules, and the two compiler errors the same choice causes with an interface and with a map.
Two wins, and the season says 0
Your Go method changed the struct, so why didn't the change stick? Jim tracks a little league season in a small Go program. Mary, the coach, reports two wins for the Hawks, so Jim calls AddWin twice. Inside the method, the count says one. On the second call, it says one again. And the season total says zero. Where did the two wins go? In five minutes you'll know, and you'll see the two compiler errors that come from the same choice.
sed -n '10,20p' main.gofunc (t Team) AddWin() { t.Wins++ fmt.Println("in AddWin:", t.Name, "has", t.Wins) } func main() { hawks := Team{Name: "Hawks"} hawks.AddWin() hawks.AddWin() fmt.Println("Season:", hawks.Name, "wins", hawks.Wins) }
go run .in AddWin: Hawks has 1 in AddWin: Hawks has 1 Season: Hawks wins 0
What a receiver is
Think of the team's scorebook. If the coach hands the scorekeeper a photocopy, every win gets written on the copy, and the real book still says zero. Hand over the book itself, and the wins stick.

In Go, that choice, a copy or the real book, is made by the part in brackets before the method's name. It's called the receiver: the value the method works on. Here, that's a Team, a struct that holds the team's name and its win count. Written as t Team, it's a value receiver: Go hands the method a copy of the team, just like any argument. Written as t star Team, it's a pointer receiver. The method gets the team's address: where the real team lives in memory. So its changes land on the real team.

So in Jim's first run, each call copied the team into t and added one to the copy. Then the method returned, and the copy was thrown away. The second call started again from zero.

The pointer receiver
So Jim adds one star. The method now receives a pointer to the team, not a copy.

Run it again: one, then two, because both calls now change the same team, and the season says the Hawks won two. He didn't even change the call, hawks dot AddWin. He doesn't need an ampersand, the symbol that takes an address. hawks is a variable, so Go takes its address for him.
go run .in AddWin: Hawks has 1 in AddWin: Hawks has 2 Season: Hawks won 2
The Go FAQ gives two rules. First: does the method need to modify the receiver? If it does, the receiver must be a pointer. Second, consistency: if some of a type's methods need a pointer, give all of them one. Jim also has a Record method that only prints the team's wins. It changes nothing, but by this rule it gets a star as well.

Interfaces need the address
That star fixed the wins, but it also changed what a Team can do. Jim writes an interface, Scorer: anything that has an AddWin method. And he stores his team in one. Guess first: does this compile? No. The compiler says Team doesn't fit Scorer, because AddWin has a pointer receiver. With that star, AddWin belongs to a pointer to a Team. A plain Team doesn't have it. An interface holds its own copy of whatever you put in it. If Go let AddWin run on that copy, the wins would land on the copy, not on hawks: the same bug Jim started with. So the compiler refuses. Store &hawks, the address of the team, and it runs.
sed -n '18,26p' main.gotype Scorer interface { AddWin() } func main() { hawks := Team{Name: "Hawks"} var s Scorer = hawks s.AddWin() fmt.Println("Season:", hawks.Record())
go run .# league ./main.go:24:17: cannot use hawks (variable of struct type Team) as Scorer value in variable declaration: Team does not implement Scorer (method AddWin has pointer receiver)
grep -n 'var s' main.go24: var s Scorer = &hawks
go run .Season: Hawks won 1
Maps need pointers
Now Jim wants the whole league, so he keeps every team in a map. A map is Go's lookup table: here it goes from a team's name to the team. Calling AddWin on a team inside the map won't compile either. The compiler says: cannot call pointer method AddWin on Team. Earlier, Go took the address of hawks for him. It can't here: a value stored in a map has no address you can take, because Go may move the entries as the map grows. A pointer method needs an address, so the compiler stops him. So Jim changes the map to hold pointers to teams, star Team instead of Team, and now the win sticks.
sed -n '14,21p' main.gofunc main() { league := map[string]Team{ "Hawks": {Name: "Hawks"}, "Owls": {Name: "Owls"}, } league["Hawks"].AddWin() fmt.Println("Hawks wins:", league["Hawks"].Wins) }
go run .# league ./main.go:19:18: cannot call pointer method AddWin on Team
sed -n '15,18p' main.goleague := map[string]*Team{ "Hawks": &Team{Name: "Hawks"}, "Owls": &Team{Name: "Owls"}, }
go run .Hawks wins: 1
Three habits. A pointer if the method changes the struct, and one kind of receiver per type: those you've seen. The third is new: a small type that never changes can use values all the way through, because copying a few fields costs almost nothing.

Recap
So: Mary's two wins landed on a copy. One star made the method work on the real team, and that same star is why the interface and the map needed an address.

If receivers make sense now, a like helps YouTube show this to more beginners, and subscribing brings the next Go idiom: context.Context.
All the lab files and commands are linked in the description. Thanks for watching Cloud Explainers.
Sources
Demos: one container on our own Mac standing in for a laptop; the little league team is made up. Every command, error and number was real. Watch the full video on YouTube.