Orta seviye
4 Ekim 2026

Hatayı bul: Go

Tek bir kod parçası. Hatayı bul ya da hata olmadığını kanıtla.

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

Soruna yol açan satırlara tıkla.

Kararın

Günde bir deneme. Cevap hemen ardından görünür.

Serini koru

Serini korumak ve ilerlemeni takip etmek için hesap oluştur.

Hesap oluştur