pagination

package
v1.0.0-beta.186 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 PagedResponse

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

func MapPagedResponse

func MapPagedResponse[Out any, In any](resp PagedResponse[In], m func(in In) Out) PagedResponse[Out]

MapPagedResponse creates a new PagedResponse with the given page, totalCount and items.

func MapPagedResponseError

func MapPagedResponseError[Out any, In any](resp PagedResponse[In], m func(in In) (Out, error)) (PagedResponse[Out], error)

MapPagedResponseError is similar to MapPagedResponse but it allows the mapping function to return an error.

func (PagedResponse[T]) MarshalJSON

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

Implement json.Marshaler interface to flatten the Page struct

type Paginator

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

Jump to

Keyboard shortcuts

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