Documentation ¶
Rendered for js/wasm
Index ¶
- Constants
- type FormatPaginator
- func (p *FormatPaginator[T]) Fetch(page ...int) ([]T, error)
- func (p *FormatPaginator[T]) FetchNext() ([]T, error)
- func (p *FormatPaginator[T]) FetchPrevious() ([]T, error)
- func (p *FormatPaginator[T]) Next() int
- func (p *FormatPaginator[T]) Previous() int
- func (p *FormatPaginator[T]) Set(querySize, limit int) *FormatPaginator[T]
Constants ¶
View Source
const PaginatorInvalid int = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FormatPaginator ¶
type FormatPaginator[T any] struct { HasNext bool `json:"has_next"` // Has next page HasPrevious bool `json:"has_previous"` // Has previous page CurrentPage int `json:"current"` // Current page number TotalPages int `json:"total_pages"` // Total pages Count int `json:"count"` Results []T `json:"results"` // Token is used to authenticate the request if it is not nil. Token *tokens.Token `json:"-"` // contains filtered or unexported fields }
Paginator does not work with TinyGo.
This package should only be compiled using the normal Go compiler.
Provides support for the token package. This is to make it easier to call authenticated API endpoints.
Example of the format:
{ "has_next": true, // Has next page "has_previous": false, // Has previous page "current": 1, // Current page number "total_pages": 10, // Total number of pages "count": 5, // Total number of results "results": [ … ] }
Simple paginator. It is used to paginate through a list of results.
Fetching these results from an API endpoint.
func New ¶
func New[T any](token *tokens.Token, formatURL string) *FormatPaginator[T]
New returns a new FormatPaginator.
Format the url with the page number ¶
Example:
New(nil, "http://127.0.0.1:8000/api/users/?page=%d&querysize=%d&limit=%d") New(nil, "http://127.0.0.1:8000/api/users/?page=%d&querysize=%d") New(nil, "http://127.0.0.1:8000/api/users/?page=%d&limit=%d") New(nil, "http://127.0.0.1:8000/api/users/?page=%d")
func (*FormatPaginator[T]) Fetch ¶
func (p *FormatPaginator[T]) Fetch(page ...int) ([]T, error)
Fetch fetches the current page of results.
func (*FormatPaginator[T]) FetchNext ¶
func (p *FormatPaginator[T]) FetchNext() ([]T, error)
FetchNext fetches the next page of results.
func (*FormatPaginator[T]) FetchPrevious ¶
func (p *FormatPaginator[T]) FetchPrevious() ([]T, error)
FetchPrevious fetches the previous page of results.
func (*FormatPaginator[T]) Next ¶
func (p *FormatPaginator[T]) Next() int
Next returns the next page number.
func (*FormatPaginator[T]) Previous ¶
func (p *FormatPaginator[T]) Previous() int
Previous returns the previous page number.
func (*FormatPaginator[T]) Set ¶
func (p *FormatPaginator[T]) Set(querySize, limit int) *FormatPaginator[T]
Set sets the query size and limit.
Click to show internal directories.
Click to hide internal directories.