Code Room
Code reviewMediumcr-g288
Subject Missing cacheLevel Mid–Senior~18 minCommon in Networking & APIs interviewsIndustries Software development, Technology

Question

Review this Go HTTP handler that returns a customer's audit-log entries. There is no `limit`, and customers with long histories time out.

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 auditHandler(w http.ResponseWriter, r *http.Request) {    cust := r.URL.Query().Get("customer")    rows, _ := db.Query("SELECT id, action, ts FROM audit WHERE customer=$1 ORDER BY ts DESC", cust)    defer rows.Close()    var out []Entry    for rows.Next() {        var e Entry        rows.Scan(&e.ID, &e.Action, &e.Ts)        out = append(out, e)    }    json.NewEncoder(w).Encode(out)}
Run or narrate your approach, then ask the coach.