Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Lx9FNLG2CqeBbVGGd9bFsP
22 lines
733 B
Go
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) }
|