- Webhook event logging repo and subscription webhook idempotency - Pagination helper (echohelpers) with cursor/offset support - Request ID and structured logging middleware - Push client improvements (FCM HTTP v1, better error handling) - Task model version column, business constraint migrations, targeted indexes - Expanded categorization chain tests - Email service and config hardening - CI workflow updates, .gitignore additions, .env.example updates Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
704 B
Go
33 lines
704 B
Go
package echohelpers
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// ParsePagination extracts limit and offset from query parameters with bounded defaults.
|
|
// maxLimit caps the maximum page size to prevent unbounded queries.
|
|
func ParsePagination(c echo.Context, maxLimit int) (limit, offset int) {
|
|
const defaultLimit = 50
|
|
|
|
limit = defaultLimit
|
|
if l := c.QueryParam("limit"); l != "" {
|
|
if parsed, err := strconv.Atoi(l); err == nil && parsed > 0 {
|
|
limit = parsed
|
|
}
|
|
}
|
|
if limit > maxLimit {
|
|
limit = maxLimit
|
|
}
|
|
|
|
offset = 0
|
|
if o := c.QueryParam("offset"); o != "" {
|
|
if parsed, err := strconv.Atoi(o); err == nil && parsed >= 0 {
|
|
offset = parsed
|
|
}
|
|
}
|
|
|
|
return limit, offset
|
|
}
|