Code Room
Code reviewMediumcr-g348
Subject Pagination bugsLevel Mid–Senior~20 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

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.

Talk through your review
Code to reviewgo
func listEvents(w http.ResponseWriter, r *http.Request) {    limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))    if limit == 0 {        limit = 50    }    rows, err := db.Query(        "SELECT id, type, payload FROM events ORDER BY id DESC LIMIT $1", limit)    if err != nil {        http.Error(w, "db error", 500)        return    }    defer rows.Close()    events := []Event{}    for rows.Next() { /* scan into events */ }    json.NewEncoder(w).Encode(events)}
Run or narrate your approach, then ask the coach.