Documentation
¶
Index ¶
Constants ¶
View Source
const ( DESC = 0 ASC = 1 DEFAULT_COUNT = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cursor ¶
type Cursor struct {
// Value should be used an an inclusive value when making queries based on this
// cursor.
// For example, in SQL: WHERE created_at <= cursor.Value (assuming descending
// sort order).
Value string
// Offset should be as offset when making queries based on this cursor.
// For example, in SQL: LIMIT cursor.Offset, 10.
Offset int
// Count is the number of items per page. Instead of using this directly you should
// use PrefetchCount() to account for prefetching.
// For example, in SQL: LIMIT 0, cursor.PrefetchCount()
Count int
// Order is an arbitrary string that should be used by Item.PaginationValue to
// decide what pagination value to return.
Order string
// Direction should control the comparison order when making queries based on this
// cursor.
// For example, in SQL:
// when Direction is DESC: WHERE created_at <= cursor.Value
// when Direction is ASC: WHERE created_at >= cursor.Value
Direction int
// Url is the url that was used to create this cursor. It's used to construct the
// next and previous urls.
Url *url.URL
Options *Options
// Items is a slice of Item objects on which we should paginate. It must be set before
// calling Next, Prev or ToPagination.
Items []Item
}
func NewCursorFromUrl ¶
func (*Cursor) PrefetchCount ¶
func (*Cursor) ToPagination ¶
func (c *Cursor) ToPagination() *Pagination
type Item ¶
type Item interface {
// PaginationValue should return a pagination value for this item.
// For example, when pagination SQL rows this could simply be the id of the row.
// If paginating a redis zset, this might be the score of the zset member.
// When paginating an array this would be the index of the array element.
PaginationValue(c *Cursor) string
}
Item is the iterface that must be implemented by objects that can be paginated.
type Options ¶
type Options struct {
// Prefetch can be set to true to indicate to the cursor that Items will contain one
// additional item, i.e. the first item from the next page.
Prefetch bool
}
type Pagination ¶
type Pagination struct {
Next *string `json:"next"`
}
Click to show internal directories.
Click to hide internal directories.