paginator

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_PAGINATION_LIMIT     = 100
	DEFAULT_MAX_PAGINATION_LIMIT = 500
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any] interface {
	HasNext() bool
	GetRow() (T, error)
	Count() (uint64, error)
}

type PaginatedResponse

type PaginatedResponse[Obj interface{}] struct {
	Links   PaginationLinks `json:"_links"`
	Count   uint64          `json:"count"`
	Results []Obj           `json:"results"`
}

type PaginationArgs

type PaginationArgs struct {
	Limit  *int `json:"limit"`
	Offset *int `json:"offset"`
	// contains filtered or unexported fields
}

func (*PaginationArgs) Parse

func (pa *PaginationArgs) Parse(c *webcontext.Context)
type PaginationLinks struct {
	Next     *string `json:"next"`
	Previous *string `json:"previous"`
}

type Paginator

type Paginator[T any] struct {
	DefaultLimit  int
	DefaultOffset int
	MaxLimit      int
}

func New

func New[T any]() *Paginator[T]

func (*Paginator[T]) Paginate

func (pr *Paginator[T]) Paginate(c *webcontext.Context, getPage func(limit, offset int) (Iterator[T], error)) (*PaginatedResponse[T], error)

Paginate mounts a PaginatedResponse. It expects a getPage function that receives limit and offset integers and returns an iterator, the total of rows and an error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL