Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLimitOffset ¶
GetLimitOffset calculates pagination parameters based on query values. It extracts the "page" and "limit" values from the provided URL query parameters, and computes the corresponding page, limit, and offset values. If the "page" or "limit" values are not provided or are invalid, it defaults to page 1 and a limit of 10, or a user-specified default limit if provided.
Parameters:
query: URL query parameters containing "page" and "limit" values. defaultLimit: Optional parameter to specify a default limit if "limit" is not provided.
Returns:
page: The current page number. limit: The number of items per page. offset: The offset for the database query, calculated as (page - 1) * limit.
func GetSorts ¶ added in v1.4.0
GetSorts extracts sorting parameters from the URL query and returns them as a bson.D object. It only allows sorting by fields specified in the allowedSort slice. If the "sort" parameter is not provided or is not in the allowedSort list, it returns an empty bson.D. Example usage:
// Simple urlQuery := url.Values{ "sort": []string{"name"}, "dir": []string{"desc"}, } // Multiple urlQuery := url.Values{ "sorts": []string{"name:asc,age:desc"}, }
Parameters:
- urlQuery: url.Values containing the URL query parameters.
- allowedSort: []string containing the list of allowed fields for sorting.
Returns:
- sorts: bson.D containing the sorting parameters.
Types ¶
This section is empty.