Documentation ¶
Index ¶
- Variables
- type Checker
- func Any() Checker
- func Bool() Checker
- func Const(value interface{}) Checker
- func FieldMap(fields Fields, defaults Defaults) Checker
- func FieldMapSet(selector string, maps []Checker) Checker
- func Float() Checker
- func ForceInt() Checker
- func Int() Checker
- func List(elem Checker) Checker
- func Map(key Checker, value Checker) Checker
- func OneOf(options ...Checker) Checker
- func SimpleRegexp() Checker
- func StrictFieldMap(fields Fields, defaults Defaults) Checker
- func String() Checker
- func StringMap(value Checker) Checker
- type Defaults
- type Fields
Constants ¶
This section is empty.
Variables ¶
var Omit omit
Omit is a marker for FieldMap and StructFieldMap defaults parameter. If a field is not present in the map and defaults to Omit, the missing field will be ommitted from the coerced map as well.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
The Coerce method of the Checker interface is called recursively when v is being validated. If err is nil, newv is used as the new value at the recursion point. If err is non-nil, v is taken as invalid and may be either ignored or error out depending on where in the schema checking process the error happened. Checkers like OneOf may continue with an alternative, for instance.
func Any ¶
func Any() Checker
Any returns a Checker that succeeds with any input value and results in the value itself unprocessed.
func Const ¶
func Const(value interface{}) Checker
Const returns a Checker that only succeeds if the input matches value exactly. The value is compared with reflect.DeepEqual.
func FieldMap ¶
FieldMap returns a Checker that accepts a map value with defined string keys. Every key has an independent checker associated, and processing will only succeed if all the values succeed individually. If a field fails to be processed, processing stops and returns with the underlying error.
Fields in defaults will be set to the provided value if not present in the coerced map. If the default value is schema.Omit, the missing field will be omitted from the coerced map.
The coerced output value has type map[string]interface{}.
func FieldMapSet ¶
FieldMapSet returns a Checker that accepts a map value checked against one of several FieldMap checkers. The actual checker used is the first one whose checker associated with the selector field processes the map correctly. If no checker processes the selector value correctly, an error is returned.
The coerced output value has type map[string]interface{}.
func Float ¶
func Float() Checker
Float returns a Checker that accepts any float value, and returns the same value consistently typed as a float64.
func ForceInt ¶
func ForceInt() Checker
ForceInt returns a Checker that accepts any integer or float value, and returns the same value consistently typed as an int. This is required in order to handle the interface{}/float64 type conversion performed by the JSON serializer used as part of the API infrastructure.
func Int ¶
func Int() Checker
Int returns a Checker that accepts any integer value, and returns the same value consistently typed as an int64.
func List ¶
List returns a Checker that accepts a slice value with values that are processed with the elem checker. If any element of the provided slice value fails to be processed, processing will stop and return with the obtained error.
The coerced output value has type []interface{}.
func Map ¶
Map returns a Checker that accepts a map value. Every key and value in the map are processed with the respective checker, and if any value fails to be coerced, processing stops and returns with the underlying error.
The coerced output value has type map[interface{}]interface{}.
func OneOf ¶
OneOf returns a Checker that attempts to Coerce the value with each of the provided checkers. The value returned by the first checker that succeeds will be returned by the OneOf checker itself. If no checker succeeds, OneOf will return an error on coercion.
func SimpleRegexp ¶
func SimpleRegexp() Checker
func StrictFieldMap ¶
StrictFieldMap returns a Checker that acts as the one returned by FieldMap, but the Checker returns an error if it encounters an unknown key.
func String ¶
func String() Checker
String returns a Checker that accepts a string value only and returns it unprocessed.
func StringMap ¶
StringMap returns a Checker that accepts a map value. Every key in the map must be a string, and every value in the map are processed with the provided checker. If any value fails to be coerced, processing stops and returns with the underlying error.
The coerced output value has type map[string]interface{}.