Code Room
Code reviewMedium
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.
Learn the concepts
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.