Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoMatch is returned when the converter cannot match a string // value with any pattern. ErrNoMatch = errors.New("does not match") // ErrUnknownOperator is returned when an unknown operator is found. ErrUnknownOperator = errors.New("unknown operator") // ErrNoFieldSpec is returned when there is no field specification, but // the field is present in a query. ErrNoFieldSpec = errors.New("no field spec") // ErrNoConverter is returned when there is no converter found. ErrNoConverter = errors.New("no converter") // ErrNoSortField is returned when there is no field specification for // the sort field from the query. ErrNoSortField = errors.New("no sort field spec") // ErrMissingField is returned when some required field is missing in // the query. ErrMissingField = errors.New("missing required filter on field") // ErrTooManyValues is returned when a single value operator is assigned // to multiple values. ErrTooManyValues = errors.New("too many values") )
Functions ¶
This section is empty.
Types ¶
type ConvertFunc ¶
ConvertFunc is a function to check and convert a string val.
func Bool ¶
func Bool() (convert ConvertFunc)
Bool tries to convert a val string to a boolean value.
func Date ¶
func Date() (convert ConvertFunc)
Date checks if a string matches some of the known patterns and tries to convert it to time.Time.
func Double ¶
func Double() (convert ConvertFunc)
Double tries to convert a val string to a float64 value.
func ObjectID ¶
func ObjectID(primitive Primitives) (convert ConvertFunc)
ObjectID checks if a string can be converted to an ObjectID value and converts it.
func (ConvertFunc) Convert ¶
func (c ConvertFunc) Convert(val string) (i interface{}, err error)
Convert calls ConvertFunc itself.
type Converter ¶
type Converter interface { // Convert checks a string val and converts it when possible to some // type. Convert(val string) (i interface{}, err error) }
Converter is an interface that converts strings to known types.
type Field ¶
type Field struct { // Converter defines a type of the field. Converter Converter // Required defines if the field is required. Required bool }
Field is a structure that holds field specification.
type Fields ¶
Fields is a map with fields specifications.
func (Fields) HasField ¶
HasField check if a field with a given name is present in the fields specifications.
func (Fields) IsRequired ¶
IsRequired returns true it a field with a given name is specified and is required.
type Parser ¶
type Parser struct { // Converter is a TypeConverter that converts unspecified fields. Converter *TypeConverter // Fields is a fields specification. Fields Fields // ValidateFields enables or disables field specification validator. // When true, the parser will return ErrNoFieldSpec for every // unspecified field in url query. ValidateFields bool // contains filtered or unexported fields }
Parser is a structure that parses url queries.
type Primitives ¶
type Primitives interface { // RegEx converts pattern and options to bson.Regex. RegEx(pattern, options string) (rx interface{}, err error) // ObjectID converts val to bson.ObjectID. ObjectID(val string) (oid interface{}, err error) // DocElem converts key and val o bson.DocElem, which is a bson.D element. DocElem(key string, val interface{}) (d interface{}, err error) }
Primitives gives access to the RegEx and ObjectID convertors.
type Query ¶
type Query struct { // Filter is a document containing query operators. Filter M // Sort is a document specifying the order in which documents should // be returned. Sort interface{} // Limit is the maximum number of documents to return. Limit int64 // Skip is a number of documents to be skipped before adding documents // to the results. Skip int64 }
Query is a structure that holds information about DB request.
type TypeConverter ¶
type TypeConverter struct { // Bool is a boolean type converter Bool ConvertFunc // Primitives gives access to mongodb-driver primitives. Primitives Primitives // Funcs checks and converts strings to known types. Funcs []ConvertFunc }
TypeConverter is a type that detects type and converts strings to that type.
func NewConverter ¶
func NewConverter(boolConvert ConvertFunc, p Primitives, convert ...ConvertFunc) (c *TypeConverter)
NewConverter creates an instance of the TypeConverter.
func NewDefaultConverter ¶
func NewDefaultConverter(p Primitives) (c *TypeConverter)
NewDefaultConverter creates a default TypeConverter instance.
func (TypeConverter) Convert ¶
func (c TypeConverter) Convert(val string) (i interface{}, err error)
Convert checks string value for patterns and converts it to matched types.