Pagination cursor exposes database offset
Review this Go API that returns a pagination cursor to clients.
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 25 min
Mark a line and say what kind of problem it is.0 findings
1type Page struct {
2 Items []Doc `json:"items"`
3 NextCursor string `json:"next_cursor"`
4}
5
6func listDocs(w http.ResponseWriter, r *http.Request) {
7 cur := r.URL.Query().Get("cursor") // raw DB offset, e.g. "40"
8 offset, _ := strconv.Atoi(cur)
9 docs := repo.Find(offset, 20) // SELECT ... OFFSET ?
10 next := strconv.Itoa(offset + 20)
11 json.NewEncoder(w).Encode(Page{Items: docs, NextCursor: next})
12}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.