Confirmé
4 octobre 2026Trouve le bug : Go
Un extrait de code. Trouve le bug, ou prouve qu'il n'y en a pas.
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}
25Clique sur les lignes qui posent problème.
Ton verdict
Une tentative par jour. La réponse s'affiche juste après.
Garde ta série
Crée un compte pour conserver ta série et suivre ta progression.