Code RoomNegative limit returns all rows
MediumPrep Room Coding #1976

Negative limit returns all rows

Code reviewNetworking & APIsMid–Senior~20 min

Review this Go list endpoint that supports a client-supplied page size.

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 listEvents(w http.ResponseWriter, r *http.Request) {
2 limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
3 if limit == 0 {
4 limit = 50
5 }
6 rows, err := db.Query(
7 "SELECT id, type, payload FROM events ORDER BY id DESC LIMIT $1", limit)
8 if err != nil {
9 http.Error(w, "db error", 500)
10 return
11 }
12 defer rows.Close()
13 events := []Event{}
14 for rows.Next() { /* scan into events */ }
15 json.NewEncoder(w).Encode(events)
16}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.