pagination

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

This package is for pagination

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLimitOffset added in v0.3.0

func GetLimitOffset(page, pageSize int) (int, int)

GetLimitOffset calculates the limit and offset for pagination based on the given page and pageSize. It returns the offset, which is the number of records to skip, and the limit, which is the number of records to return. The offset is calculated as (page - 1) * pageSize, and the limit is set to pageSize.

func GetPageAndPageSize

func GetPageAndPageSize(page, pageSize int) (int, int)

GetPageAndPageSize validates the input page and pageSize and returns optimized values. If the page value is less than or equal to zero, it defaults to 'defaultPage'. If pageSize exceeds 'maxPageSize', it is set to 'maxPageSize'. This allows pageSize to be less than or equal to zero, accommodating APIs that use list API as a "ping" endpoint. Returns: Optimized 'page' and 'pageSize'.

func GetTotalPage

func GetTotalPage(totalRecords int64, pageSize int) int

GetTotalPage calculates the total number of pages needed to display all records. It takes the total number of records and the desired page size as input. The output is the minimum number of pages required to display all records, given that each page displays at most 'pageSize' records.

Types

type PagingOptions added in v0.3.0

type PagingOptions struct {
	Page     int `json:"page" default:"1"`
	PageSize int `json:"pageSize" default:"20"`
}

Jump to

Keyboard shortcuts

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