filter

package
v0.0.0-...-a57f64e Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	Page         int
	PageSize     int
	Sort         string
	SortSafeList []string
}

func (Filter) Limit

func (f Filter) Limit() int

func (Filter) Offset

func (f Filter) Offset() int

func (Filter) SortColumn

func (f Filter) SortColumn() string

Check that the client-provided Sort field matches one of the entries in our safelist and if it does, extract the column name from the Sort field by stripping the leading hyphen character (if one exists).

func (Filter) SortDirection

func (f Filter) SortDirection() string

Return the sort direction ("ASC" or "DESC") depending on the prefix character of the Sort field.

func (Filter) Validate

func (f Filter) Validate(v *validator.Validator)

type Metadata

type Metadata struct {
	CurrentPage  int `json:"current_page,omitempty"`
	PageSize     int `json:"page_size,omitempty"`
	FirstPage    int `json:"first_page,omitempty"`
	LastPage     int `json:"last_page,omitempty"`
	TotalRecords int `json:"total_records,omitempty"`
}

Define a new Metadata struct for holding the pagination metadata.

func CalculateMetadata

func CalculateMetadata(totalRecords, page, pageSize int) Metadata

The calculateMetadata() function calculates the appropriate pagination metadata values given the total number of records, current page, and page size values. Note that the last page value is calculated using the math.Ceil() function, which rounds up a float to the nearest integer. So, for example, if there were 12 records in total and a page size of 5, the last page value would be math.Ceil(12/5) = 3.

Jump to

Keyboard shortcuts

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