pagination

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package pagination provides utilities for handling pagination in HTTP requests.

Index

Constants

View Source
const (
	// DefaultPage is the default page number when not specified.
	DefaultPage = 1
	// DefaultPerPage is the default number of items per page.
	DefaultPerPage = 20
	// MaxPerPage is the maximum allowed items per page.
	MaxPerPage = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Params

type Params struct {
	Page    int
	PerPage int
	Offset  int
}

Params contains pagination parameters extracted from an HTTP request.

func FromRequest

func FromRequest(r *http.Request) Params

FromRequest extracts pagination parameters from an HTTP request. It reads "page" and "per_page" query parameters and validates them.

func FromValues

func FromValues(page, perPage int) Params

FromValues creates pagination params from explicit values. Useful for programmatic pagination without HTTP context.

type Result

type Result struct {
	Page       int   `json:"page"`
	PerPage    int   `json:"per_page"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"total_pages"`
	HasNext    bool  `json:"has_next"`
	HasPrev    bool  `json:"has_prev"`
}

Result contains pagination metadata for a response.

func NewResult

func NewResult(params Params, total int64) Result

NewResult creates a pagination result from params and total count.

Jump to

Keyboard shortcuts

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