pagination

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOffsetParameter represents an error case where an invalid offset value is provided
	ErrInvalidOffsetParameter = errors.New("invalid offset query parameter")

	// ErrOffsetOverTotalCount represents an error case where the given offset value is larger than the total count
	ErrOffsetOverTotalCount = errors.New("offset query parameter is larger than the total count of jobs")

	// ErrInvalidLimitParameter represents an error case where an invalid limit value is provided
	ErrInvalidLimitParameter = errors.New("invalid limit query parameter")

	// ErrLimitOverMax represents an error case where the given limit value is larger than the maximum allowed
	ErrLimitOverMax = errors.New("limit query parameter is larger than the maximum allowed")
)

Functions

This section is empty.

Types

type PaginatedResponse

type PaginatedResponse struct {
	Count      int `json:"count"`
	Offset     int `json:"offset"`
	Limit      int `json:"limit"`
	TotalCount int `json:"total_count"`
}

PaginatedResponse represents the pagination related values that go into list based response

type Paginator

type Paginator struct {
	DefaultLimit    int
	DefaultOffset   int
	DefaultMaxLimit int
}

Paginator is a type to hold pagination related defaults, and provides helper functions using the defaults if needed

func NewPaginator

func NewPaginator(defaultLimit, defaultOffset, defaultMaxLimit int) *Paginator

NewPaginator creates a new instance

func (*Paginator) ValidatePaginationParameters

func (p *Paginator) ValidatePaginationParameters(offsetParameter string, limitParameter string, totalCount int) (offset int, limit int, err error)

ValidatePaginationParameters returns pagination related values based on the given request

Jump to

Keyboard shortcuts

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