Page Query

Definition

PageQuery is a ​​generic pagination query parameter structure​​ designed to standardize common list query requirements such as pagination and sorting. PageQuery has three fields, PageNumber and PageSize is used to build the paging clause, and Sort is used to build the sorting clause. PageQuery implements the Query interface.

package core

type PageQuery struct {
	PageNumber *int    `json:"page,omitempty"`
	PageSize   *int    `json:"size,omitempty"`
	Sort       *string `json:"sort,omitempty"`
}

Usage

When defining query objects, embed the PageQuery struct through composition to reuse standardized pagination and sorting functionality.

type UserQuery struct {
    PageQuery
    ScoreLt  *int
    MemoNull *bool
    Deleted  *bool
}

Paging

Sorting

The Sort string should follow regexp.MustCompile("(?i)(\w+)(,(asC|dEsc))?;?")

Last updated

Was this helpful?