Code Room
Code reviewHardcr-g612
Subject Storage toctouLevel Senior–Staff~22 minCommon in Security · Storage & CDN interviewsIndustries Software development

Question

Review this Go handler that serves user files.

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 serveTempFile(w http.ResponseWriter, name string) error {    path := filepath.Join("/var/tmp/exports", name)    info, err := os.Stat(path)    if err != nil {        return err    }    if info.Size() > maxExportBytes {        return errTooLarge    }    data, err := os.ReadFile(path)   // open + read after the stat    if err != nil {        return err    }    _, err = w.Write(data)    return err}
Run or narrate your approach, then ask the coach.