NewGit
Sign in

Paginate the product list !2

Open @demo wants to merge AGit mr-2 main opened
Versions
Ready to merge
Changes in v1 against the merge base with main
1 file changed+10−0
products.go +10−0 View file
Changes to products.go: 10 additions, 0 deletions
Old lineNew lineChangeCode
@@ -32,3 +32,13 @@ func getProduct(w http.ResponseWriter, r *http.Request) {
3232 }
3333 }
3434}
35added
36addedfunc page(r *http.Request) (start, end int) {
37added n, _ := strconv.Atoi(r.URL.Query().Get("page"))
38added per, _ := strconv.Atoi(r.URL.Query().Get("per_page"))
39added if per <= 0 {
40added per = 20
41added }
42added start = n * per
43added return start, start + per
44added}