Mid-Level
August 19, 2026Spot the bug: Go
One snippet. Find the bug, or prove there isn't one.
go
1package users
2
3import "sync"
4
5type User struct {
6 ID string
7 Name string
8}
9
10var (
11 mu sync.Mutex
12 cache = map[string]*User{}
13)
14
15func GetUser(id string, fetch func() *User) *User {
16 mu.Lock()
17 defer mu.Unlock()
18 if u, ok := cache[id]; ok {
19 return u
20 }
21 u := fetch()
22 cache[id] = u
23 return u
24}Click the lines that carry the problem.
Your verdict
One attempt per day. The answer shows up right after.
Keep your streak
Create an account to keep your streak and track your progress.