Mid-Level
October 4, 2026

Spot the bug: Go

One snippet. Find the bug, or prove there isn't one.

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

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.

Create an account