Code RoomTransfer amount not validated
MediumPrep Room Coding #1768

Transfer amount not validated

Code reviewCode quality & reviewMid–Senior~20 min

Review this Go money-transfer handler.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1func TransferHandler(w http.ResponseWriter, r *http.Request) {
2 var req struct {
3 To string `json:"to"`
4 Amount float64 `json:"amount"`
5 }
6 if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
7 http.Error(w, "bad request", 400)
8 return
9 }
10 if req.Amount > balance(r.Context()) {
11 http.Error(w, "insufficient funds", 400)
12 return
13 }
14 debit(req.To, req.Amount)
15 w.WriteHeader(204)
16}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.