Files
nmon/internal/api/paging.go
jleung f85c3ef781
Some checks failed
ci / lint (push) Has been cancelled
ci / test (ubuntu-24.04-arm) (push) Has been cancelled
ci / test (ubuntu-latest) (push) Has been cancelled
ci / postgres (push) Has been cancelled
ci / openapi (push) Has been cancelled
M3: Go API per UI contract, embedded UI, openapi compat check, nmon-devtools, live gate + screenshots; M4 WP1 reachability and dependency suppression
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
2026-10-22 20:34:14 +00:00

22 lines
733 B
Go

package api
// PageParams are the paging query parameters every list takes. The maximum is
// enforced by validation, so a larger per_page is a 422 problem.
type PageParams struct {
Page int64 `query:"page" minimum:"1" default:"1" doc:"1-based page number."`
PerPage int64 `query:"per_page" minimum:"1" maximum:"1000" default:"100" doc:"Items per page; at most 1,000."`
}
// offset and limit translate the page into store terms.
func (p PageParams) offset() int64 { return (max(p.Page, 1) - 1) * p.limit() }
func (p PageParams) limit() int64 {
if p.PerPage <= 0 {
return 100
}
return p.PerPage
}
// pageNo is the page number echoed in the response envelope.
func (p PageParams) pageNo() int64 { return max(p.Page, 1) }