Documentation
¶
Overview ¶
Package qsparser is used to parse various query strings.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SearchField ¶
type SearchField struct { // SearchVal is the search value for the field SearchVal *string // SearchOp is the search operation for the field SearchOp *string // Visible specifies whether the field is visible to the consumer or not Visible *bool }
Field hold values for a single field
type SearchOrder ¶
type SearchOrder struct { // Fields is the field name to order by Fields []string // Directions is the direction to order by // A value of nil indicates that all fields are sorted in the same direction Directions []string }
Order specifies the order of fields Directions must be either nil or equals in length to that of Fields
type SearchParams ¶
type SearchParams struct { // Draw can be used to ensure order of requests and responses for asynchronous requests Draw *int // Page is used for pagination and represents the current page number Page *int // PerPage is used for pagination and represents the number of rows to return for each page PerPage *int // GlobalSearchVal represents a global search value that can be used to search across multiple fields GlobalSearchVal *string // Order represents the field order Order *SearchOrder // Fields represents the fields and their options Fields map[string]*SearchField }
SearchParams holds the search parameters nil values indicate the parameter was not specified in the query string
func ParseSearchQuery ¶
func ParseSearchQuery(r *http.Request) (sp *SearchParams, err error)
ParseSearchQuery parses a HTTP request's query string into a SeachParams It supports global search, field search and pagination.
The supported query string parameters are:
* draw - an optional integer value that can be used to ensure the order of quests and responses of asynchronous requests * page - an optional integer value that can be used as the requested page in pagination * per_page - an optional integer value that can be used as the requested number of rows returned in pagination * search - an optional string value that can be used as a global search value * ord - a complex value (see below) that specifies the order of the requested fields for field search * f - a complex value (see below) that specifies the field names, search values and search operator of the requested fields for field search
The package doesn't assume anything about the validity or possible values of the parameter values. Is is the job of the consumer to validate those.
The 'ord' parameter format is any one of:
`ord[fields]=value1,value2,...`
Where `value1,value2,...` is a comma-separated list of strings representing the field names to order by.
`ord[dir]=value1,value2,...`
Where `value1,value2,...` is a comma-separated list of strings representing the direction in which the fields should be ordered.
If `ord[dir]` is specified the number of values must be be equal to the number of values in ord[fields].
None of the values may contain commas.
Example:
Order by name ascending and age descending:
`ord[fields]=name,age&ord[dir]=asc,desc`
The 'f' parameter format is any of:
`f[field_name][search][value]=value`
Where `field_name` is a string representing a field name and `value` a string representing the search value for that field.
`f[field_name][search][op]=value`
Where `field_name` is a string representing a field name and `value` a string representing the search operator for that field.
`f[field_name][visible]=value`
Where `field_name` is a string representing a field name and `value` is a boolean (true or false).
This parameter is used to inform about the visibility of a field, e.g. if it should be hidden from view.
Examples:
1) Show records where 'name' eq(==) 'Peter' indicating that the field should be made visible:
`f[name][search][value]=Peter&f[name][search][op]=eq&f[name][search][visible]=true`
2) Show records where 'age' ge(>=) '20' indicating that the field should not be made visible:
`f[age][search][value]=20&f[age][search][op]=ge&f[age][search][visible]=false`
func (*SearchParams) SetRawQuery ¶
func (sp *SearchParams) SetRawQuery(req *http.Request)