pagination

package
v0.143.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPage defines the default page number
	DefaultPage = 1
	// DefaultPageSize defines the default number of items per page
	// TODO: change to 15 when all clients are updated
	DefaultPageSize = 50
)
View Source
const DefaultCursorLimit = 10

DefaultCursorLimit is the default number of items per page for cursor-based pagination

Variables

This section is empty.

Functions

func EncodeCursor added in v0.135.0

func EncodeCursor(t time.Time, uuid uuid.UUID) string

EncodeCursor generates a base64 encoded representation of a timestamp + identifier

func IsCursorPaginationError added in v0.135.0

func IsCursorPaginationError(err error) bool

IsCursorPaginationError checks if the error is an CursorPaginationError

func IsOffsetPaginationError

func IsOffsetPaginationError(err error) bool

IsOffsetPaginationError checks if the error is an OffsetPaginationError

Types

type Cursor added in v0.135.0

type Cursor struct {
	Timestamp *time.Time
	ID        *uuid.UUID
}

Cursor is a struct that holds the timestamp and identifier of a record

type CursorOptions added in v0.135.0

type CursorOptions struct {
	Cursor *Cursor
	Limit  int
}

CursorOptions is a struct that holds the cursor and limit for pagination

func NewCursor added in v0.135.0

func NewCursor(c string, l int) (*CursorOptions, error)

type CursorPaginationError added in v0.135.0

type CursorPaginationError struct {
	// contains filtered or unexported fields
}

CursorPaginationError is the error type for cursor-based pagination

func NewCursorPaginationError added in v0.135.0

func NewCursorPaginationError(err error) CursorPaginationError

NewCursorPaginationError creates a new CursorPaginationError with the provided error

func (CursorPaginationError) Error added in v0.135.0

func (e CursorPaginationError) Error() string

Error returns the error message

type OffsetPaginationError

type OffsetPaginationError struct {
	// contains filtered or unexported fields
}

OffsetPaginationError is the error type for page-based pagination

func NewOffsetPaginationErrorStr

func NewOffsetPaginationErrorStr(errMsg string) OffsetPaginationError

NewOffsetPaginationErrorStr creates a new OffsetPaginationError with the provided error message

func (OffsetPaginationError) Error

func (e OffsetPaginationError) Error() string

Error returns the error message

func (OffsetPaginationError) Unwrap

func (e OffsetPaginationError) Unwrap() error

Unwrap returns the wrapped error

type OffsetPaginationOpts

type OffsetPaginationOpts struct {
	// contains filtered or unexported fields
}

OffsetPaginationOpts is the options for page-based pagination

func NewDefaultOffsetPaginationOpts

func NewDefaultOffsetPaginationOpts() *OffsetPaginationOpts

NewDefaultOffsetPaginationOpts creates a new OffsetPaginationOpts with default values

func NewOffsetPaginationOpts

func NewOffsetPaginationOpts(offset, limit int) (*OffsetPaginationOpts, error)

NewOffsetPaginationOpts creates a new OffsetPaginationOpts with the provided page and pageSize

func (*OffsetPaginationOpts) Limit

func (o *OffsetPaginationOpts) Limit() int

Limit returns the number of items per page

func (*OffsetPaginationOpts) Offset

func (o *OffsetPaginationOpts) Offset() int

Offset returns the page number

Jump to

Keyboard shortcuts

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