pagination

package
v1.0.0-beta.225 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_SAFE_ITER = 10_000

Variables

This section is empty.

Functions

func CollectAll

func CollectAll[T any](ctx context.Context, paginator Paginator[T], pageSize int) ([]T, error)

CollectAll collects all items from the paginator going page by page.

Types

type InvalidError

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

func (InvalidError) Error

func (e InvalidError) Error() string

type Page

type Page struct {
	PageSize   int `json:"pageSize"`
	PageNumber int `json:"page"`
}

func NewPage

func NewPage(pageNumber int, pageSize int) Page

NewPage creates a new Page with the given pageNumber and pageSize.

func NewPageFromRef

func NewPageFromRef(pageNumber *int, pageSize *int) Page

NewPageFromRef creates a new Page from pointers to pageNumber and pageSize. Useful for handling query parameters.

func (Page) IsZero

func (p Page) IsZero() bool

func (Page) Limit

func (p Page) Limit() int

func (Page) Offset

func (p Page) Offset() int

func (Page) Validate

func (p Page) Validate() error

type Paginator

type Paginator[T any] interface {
	Paginate(ctx context.Context, page Page) (Result[T], error)
}

func NewPaginator

func NewPaginator[T any](fn func(ctx context.Context, page Page) (Result[T], error)) Paginator[T]

type Result

type Result[T any] struct {
	Page       Page `json:"-"`
	TotalCount int  `json:"totalCount"`
	Items      []T  `json:"items"`
}

func MapResult

func MapResult[Out any, In any](resp Result[In], m func(in In) Out) Result[Out]

MapResult creates a new Result with the given page, totalCount and items.

func MapResultErr

func MapResultErr[Out any, In any](resp Result[In], m func(in In) (Out, error)) (Result[Out], error)

MapResultErr is similar to MapResult but it allows the mapping function to return an error.

func (Result[T]) MarshalJSON

func (p Result[T]) MarshalJSON() ([]byte, error)

Implement json.Marshaler interface to flatten the Page struct

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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