Intermedio
4 ottobre 2026

Trova il bug: Go

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

go
1package main
2
3import (
4	"encoding/json"
5	"net/http"
6)
7
8type Payment struct {
9	Amount float64 `json:"amount"`
10	UserID string  `json:"userId"`
11}
12
13func createPayment(w http.ResponseWriter, r *http.Request) {
14	var p Payment
15	if err := json.NewDecoder(r.Body).Decode(&p); err != nil {
16		http.Error(w, "invalid json", 400)
17		return
18	}
19	if err := chargeAccount(p.UserID, p.Amount); err != nil {
20		http.Error(w, "charge failed", 500)
21		return
22	}
23	w.WriteHeader(201)
24}
25

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