Documentation
¶
Index ¶
Constants ¶
const ( NamespaceCodeKey = "namespaceCode" ProjectCodeKey = "projectCode" NameKey = "name" )
Variables ¶
This section is empty.
Functions ¶
func EncodeCursor ¶ added in v0.2.0
EncodeCursor renders a cursor as the opaque string returned in Next.
Types ¶
type Cursor ¶ added in v0.2.0
type Cursor struct {
// AfterID is the last id of the previous page. The next page starts above it.
AfterID int64 `json:"id"`
// Total is the row count measured when the listing started.
Total int `json:"total"`
// Delivered is how many rows the previous pages returned.
Delivered int `json:"delivered"`
}
Cursor is the position and loop state of a keyset-paginated listing.
It is encoded into an opaque string handed to the client and echoed back unchanged, so its shape stays a server implementation detail. It carries more than the position on purpose:
- Total, so the count is computed once on the first page instead of on every page. A full sync of a large project otherwise spends most of its time counting the same rows over and over.
- Delivered, so the response can keep reporting Offset and existing clients' HasMore keeps working unchanged.
func DecodeCursor ¶ added in v0.2.0
DecodeCursor parses a cursor received from a client. A malformed cursor is a client error, not a server one: it is reported so the caller can answer 400 rather than silently falling back to offset pagination, which would restart the listing from the top and loop forever.
type ListPage ¶ added in v0.2.0
ListPage holds the pagination fields of a listing response, shared by every endpoint that pages through published resources.
func NewListPage ¶ added in v0.2.0
func NewListPage(pagination *commonTypes.PaginationInput, cursor *Cursor, total int64, count int, lastID int64) (ListPage, error)
NewListPage computes the pagination fields of a response. cursor is nil when the client paginates by offset, in which case total is the count the query measured; otherwise the total and the position come from the cursor, so the response looks the same either way and clients relying on Offset and Total keep working.
count is the number of rows in this page and lastID the id of its last row, used to build the cursor of the following page.