pagination

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLimit = errors.New("invalid limit")

Functions

This section is empty.

Types

type Client

type Client struct {
	// DefaultLimit is the default number of items to return if no limit is specified.
	DefaultLimit int
	// MinLimit is the minimum number of items that can be requested.
	MinLimit int
	// MaxLimit is the maximum number of items that can be requested.
	MaxLimit int
}

func New

func New(defaultLimit, minLimit, maxLimit int) *Client

func (*Client) Parse

func (c *Client) Parse(params ParseParams) (*Parsed, error)

Parse takes the request parameters passed by the user and returns a parsed pagination object that can be used to query the database. It validates the limit and returns an error if it's invalid.

type ParseParams

type ParseParams struct {
	// Optional, if not provided, default limit will be used.
	Limit *int
	// Optional, if not provided, no offset will be applied.
	Until *time.Time
	// Optional, if not provided, no offset will be applied.
	Since *time.Time
}

type Parsed

type Parsed struct {
	Limit int
	Until *time.Time
	Since *time.Time
}

type Response

type Response struct {
	Count int
	Next  *time.Time
	Prev  *time.Time
}

func GetResponseData

func GetResponseData[T any](items []T, getTimeColumn func(item T) time.Time) *Response

GetResponseData takes a slice of items, most presumably from a database query, and returns a Response object that contains the count of items and the next and previous timestamps for pagination.

Jump to

Keyboard shortcuts

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