page

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPageNumber is the default page number for pagination (starts from 1).
	DefaultPageNumber int = 1
	// DefaultPageSize is the default page size for pagination.
	DefaultPageSize int = 15
	// MaxPageSize is the maximum allowed page size to prevent excessive data loading.
	MaxPageSize int = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Page

type Page[T any] struct {
	Page  int   `json:"page"`
	Size  int   `json:"size"`
	Total int64 `json:"total"`
	Items []T   `json:"items"`
}

Page represents a paginated response with metadata and items.

func New

func New[T any](pageable Pageable, total int64, items []T) Page[T]

New creates a new page from pageable parameters, total count, and items. It ensures items is never nil and returns an empty slice if needed.

func (Page[T]) HasNext

func (page Page[T]) HasNext() bool

HasNext returns true if there are more pages after the current one.

func (Page[T]) HasPrevious

func (page Page[T]) HasPrevious() bool

HasPrevious returns true if there are pages before the current one.

func (Page[T]) TotalPages

func (page Page[T]) TotalPages() int

TotalPages returns the total number of pages based on the total count.

type Pageable

type Pageable struct {
	api.M

	Page int `json:"page"` // 1-based
	Size int `json:"size"`
}

Pageable represents pagination parameters for querying data.

func (*Pageable) Normalize

func (p *Pageable) Normalize(size ...int)

Normalize normalizes the pageable parameters.

func (Pageable) Offset

func (p Pageable) Offset() int

Offset returns the zero-based offset for database queries.

Jump to

Keyboard shortcuts

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