Documentation ¶
Index ¶
Constants ¶
const ( FilterTypeProperty = "property" FilterTypeOperator = "operator" )
const ( MinPage = 1 // MinPage represents the minimum allowed value for the pagination query's Page parameter. MinPerPage = 1 // MinPerPage represents the minimum allowed value for the pagination query's PerPage parameter. DefaultPerPage = 10 // DefaultPerPage represents the default value for the pagination query's PerPage parameter. MaxPerPage = 100 // MaxPerPage represents the maximum allowed value for the pagination query's PerPage parameter. )
const ( OrderAsc = "asc" OrderDesc = "desc" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct { Type string `json:"type,omitempty"` Params interface{} `json:"params,omitempty"` }
func (*Filter) UnmarshalJSON ¶
type FilterOperator ¶
type FilterOperator struct { // Name is the filter operator (e.g., "and", "or"). Name string `json:"name"` }
FilterOperator represents a JSON representation of a filter operator in a query (e.g., "and", "or" in MongoDB queries).
type FilterProperty ¶
type FilterProperty struct { // Name is the attribute to be observed in the operation. Name string `json:"name"` // Operator is the operation (e.g., "eq" for equal). Operator string `json:"operator"` // Value is the value used in the operation. (e.g., "eq" operations use Value to determine the value to be equal). Value interface{} `json:"value"` }
FilterProperty is a JSON representation of a property expression in a query.
Name is the attribute to be observed in the operation, Operator is the operation, and Value is the value used in the operation. While Name can be any string, the Operator must be supported by the implementation, and the Value is the value used in the operation.
Each operator has its own implementation, and one operator can have multiple implementations. For that reason, the operator must be converted to a useful value using build methods.
Examples: A FilterProperty with Operator "gt", Name "count", and Value 12 will filter documents with the attribute "count" greater than 12. Another FilterProperty with Operator "eq", Name "alias", and Value "foobar" will filter documents with the attribute "alias" equal to "foobar".
type Filters ¶
type Filters struct { // Raw holds the raw data of the filter and it's a base64-encoded JSON. Raw string `query:"filter"` // Data stores the decoded filters; it's automatically populated with the Unmarshal method. Data []Filter }
Filters represents a set of filters that can be applied to queries.
func NewFilters ¶
func NewFilters() *Filters
NewFilters creates a new instance of Filters with an empty Data slice.
type Paginator ¶
type Paginator struct { // Page represents the current page number. Page int `query:"page"` // PerPage represents the number of items per page. PerPage int `query:"per_page"` }
Paginator represents the paginator parameters in a query.
func NewPaginator ¶
func NewPaginator() *Paginator
NewPaginator creates and returns a new Paginator instance with MinPage and DefaultPerPage.
func (*Paginator) Normalize ¶
func (p *Paginator) Normalize()
Normalize ensures valid values for Page and PerPage in the pagination query. If query.PerPage is less than zero, it is set to `DefaultPerPage`. If query.Page is less than one, it is set to `MinPage`. The maximum allowed value for query.PerPage is `MaxPerPage`.
type Sorter ¶
type Sorter struct { By string `query:"sort_by"` Order string `query:"order_by" validate:"omitempty,oneof=asc desc"` }
Sorter represents the sorting order in a query.