Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RequestParams ¶
type RequestParams struct { //RawQuery contains the raw query string Values object RawQuery url.Values `json:"raw_query"` //Q (selector) holds the query parameters specified in the request. //Defaults to bson.M{}. Q bson.M `json:"selector"` //S (scope) specifies the fields to be included in the result set. //Defaults to bson.M{}. A nil scope will return the entire dataset. S bson.M `json:"scope"` //L (limit) specifies the maximum number of records to be retrieved //for a given request. Limit defaults to 10. L int `json:"limit"` //F (offset) specifies the number of records to skip in the result set. //This is useful for paging through large result sets. //F defaults to 0. F int `json:"offset"` }
RequestParams holds state parsed from a given HTTP request
func ExtractRequestParams ¶
func ExtractRequestParams(query url.Values) (p *RequestParams)
ExtractRequestParams initializes the RequestParams object.
func (*RequestParams) Limit ¶
func (p *RequestParams) Limit() int
Limit returns an integer value indicating the size of the result set returned from the database.
func (*RequestParams) Offset ¶
func (p *RequestParams) Offset() int
Offset returns an integer value indicating the number of records to skip when returning a result set.
func (*RequestParams) Scope ¶
func (p *RequestParams) Scope() bson.M
Scope returns a mongodb bson.M object containing the set of fields to be returned from mongodb. Empty scope objects will return all fields from the database.
func (*RequestParams) Selector ¶
func (p *RequestParams) Selector() bson.M
Selector returns a mongodb bson.M object containing the query parameters supplied in the HTTP request.
type ResponseWrapper ¶
type ResponseWrapper struct { //Status indicates the result of a request as "success" or "error" Status string `json:"status"` //Data holds the payload of the response Data interface{} `json:"data,omitempty"` //Message contains the nature of an error Message string `json:"message,omitempty"` //Count contains the number of records in the result set Count int `json:"count,omitempty"` }
ResponseWrapper provides a standard structure for API responses.
func CollectionWrapper ¶
func CollectionWrapper(data interface{}, count int) (rsp *ResponseWrapper)
CollectionWrapper is for successful reuqests that have the potential to yield multiple results.
func ErrorWrapper ¶
func ErrorWrapper(message string) (rsp *ResponseWrapper)
ErrorWrapper is for requests that yield no results due to an error.
func SuccessWrapper ¶
func SuccessWrapper(data interface{}) (rsp *ResponseWrapper)
SuccessWrapper is for successful requests that yield a single result value.