Paginate the product list !2
Versions
Ready to merge
Changes in v1 against the merge base with main
1 file changed+10−0
- Modified:products.go+10−0
products.go +10−0
| Old line | New line | Change | Code |
|---|---|---|---|
| @@ -32,3 +32,13 @@ func getProduct(w http.ResponseWriter, r *http.Request) { | |||
| 32 | 32 | } | |
| 33 | 33 | } | |
| 34 | 34 | } | |
| 35 | added | ||
| 36 | added | func page(r *http.Request) (start, end int) { | |
| 37 | added | n, _ := strconv.Atoi(r.URL.Query().Get("page")) | |
| 38 | added | per, _ := strconv.Atoi(r.URL.Query().Get("per_page")) | |
| 39 | added | if per <= 0 { | |
| 40 | added | per = 20 | |
| 41 | added | } | |
| 42 | added | start = n * per | |
| 43 | added | return start, start + per | |
| 44 | added | } | |