pagination

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(resultCount, limit int) int

Count calculates the page count with the given resultCount of a pagination query and a page limit.

func FilterExtractValues added in v1.0.0

func FilterExtractValues(values *fasthttp.Args, column string) (result []string, param string, query *fasthttp.Args)

FilterExtractValues extracts the values for a specific column from the pagination filter arguments.

values: needs to be a querystring in the format "?column_name:value1,value2,...;other_column:other_value&"

func FilterSetValues added in v1.0.0

func FilterSetValues(values *fasthttp.Args, param, column string, valuesToAdd ...string)

FilterSetValues adds or updates values for a specific column in the pagination filter arguments.

func Offset

func Offset(page, limit int) int

Offset calculates the offset with the page and limit params

func Query

func Query(args *fasthttp.Args, allowedColumns map[string]bool) func(*gorm.DB) *gorm.DB

Query builds a pagination query with the provided values and checks the input columns against the allowedColumns list. Returns a gorm query to be used in the function or an error.

func Sort added in v0.0.3

func Sort(args *fasthttp.Args, allowedColumns map[string]bool) func(*gorm.DB) *gorm.DB

Sort builds a sort query with the provided values and checks the input columns against the allowedColumns list. Returns a gorm query to be used in the function or an error.

Types

type Model

type Model struct {
	Limit     int         `json:"limit"`
	Page      int         `json:"page"`
	PageCount int         `json:"pageCount"`
	Total     int         `json:"total"`
	Result    interface{} `json:"result"`
}

Model struct is used to return paginated data.

func CreatePaginationModel

func CreatePaginationModel(limit, page, pageCount, total int, result interface{}) Model

CreatePaginationModel is a helper to be able to return a pagination model in a single line

Jump to

Keyboard shortcuts

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