Intermedio
19 agosto 2026

Trova il bug: Go

Uno snippet di codice. Trova il bug, o dimostra che non ce n'è.

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}

Clicca sulle righe che causano il problema.

Il tuo verdetto

Un tentativo al giorno. La risposta appare subito dopo.

Mantieni la tua serie

Crea un account per conservare la tua serie e seguire i tuoi progressi.

Crea un account