Documentation ¶
Index ¶
- func StringRangeValidator(min, max int) func(string) bool
- func StringRegexValidator(r *regexp.Regexp) func(string) bool
- func StringRenderer(text string) *stringRenderer
- type BoolQueryParameterMapper
- type BooleanValidator
- type Context
- type Discriminator
- type EnumeratedValuesValidator
- type FlattenedPathError
- type IntQueryParameterMapper
- type IntegerValidator
- type InterfaceValidator
- type LossyUint64Validator
- type MapMap
- type MappedField
- type MultiValidationError
- type ParameterMap
- type PrimitiveMap
- type QueryMap
- func (qm QueryMap) Decode(urlQuery map[string][]string, dst interface{}) error
- func (qm QueryMap) DecodeHeader(headers http.Header, dst interface{}) error
- func (qm QueryMap) Encode(src interface{}, urlQuery map[string][]string) error
- func (qm QueryMap) EncodeHeader(src interface{}, headers http.Header) error
- type QueryParameterMapper
- type RawMessage
- type RegisterableTypeMap
- type RenderInfo
- type SliceMap
- type StrPointerQueryParameterMapper
- type StrSliceQueryParameterMapper
- type StringQueryParameterMapper
- type StringValidator
- type StringsSliceMapper
- type StructMap
- type TimeMap
- type TimeQueryParameterMapper
- type TypeMap
- func MapOf(elem TypeMap) TypeMap
- func NewPrimitiveMap(v Validator) TypeMap
- func NewStringsSliceMapper(sv *StringValidator) TypeMap
- func SliceOf(elem TypeMap) TypeMap
- func SliceOfMax(elem TypeMap, max int) TypeMap
- func SliceOfMin(elem TypeMap, min int) TypeMap
- func SliceOfRange(elem TypeMap, min, max int) TypeMap
- func Time() TypeMap
- func VariableType(switchOnFieldName string, types map[string]TypeMap) TypeMap
- type TypeMapper
- type UUIDStringValidator
- type UintQueryParameterMapper
- type ValidationError
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringRangeValidator ¶
Some useful validators
func StringRenderer ¶
func StringRenderer(text string) *stringRenderer
Types ¶
type BoolQueryParameterMapper ¶
type BoolQueryParameterMapper struct { // Returns true on nil slices and empty strings EmptyTrue bool }
Probably doesn't need Validators
func (BoolQueryParameterMapper) Decode ¶
func (bqpm BoolQueryParameterMapper) Decode(src ...string) (interface{}, error)
type BooleanValidator ¶
type BooleanValidator struct{}
func (*BooleanValidator) Validate ¶
func (v *BooleanValidator) Validate(value interface{}) (interface{}, error)
type Discriminator ¶
The discrimator is used to handle cases in which a JSON property may be more than one type (e.g. Human.Pet may be type Dog or Cat). PropertyName is the name of said property and Mapping is a map between the possible types (as strings) and the appropriate TypeMap corresponding to the given type. See https://swagger.io/specification/#discriminatorObject for more information.
type EnumeratedValuesValidator ¶
func (*EnumeratedValuesValidator) Validate ¶
func (v *EnumeratedValuesValidator) Validate(value interface{}) (interface{}, error)
type FlattenedPathError ¶
func NewFlattenedPathError ¶
func NewFlattenedPathError(path, message string) *FlattenedPathError
func (*FlattenedPathError) String ¶
func (e *FlattenedPathError) String() string
type IntQueryParameterMapper ¶
func (IntQueryParameterMapper) Decode ¶
func (iqpm IntQueryParameterMapper) Decode(src ...string) (interface{}, error)
type IntegerValidator ¶
TODO: The spectrum of numeric types deserves more thought. Do we ship independent validators for each?
func (*IntegerValidator) Validate ¶
func (v *IntegerValidator) Validate(value interface{}) (interface{}, error)
type InterfaceValidator ¶
type InterfaceValidator struct{}
func Interface ¶
func Interface() *InterfaceValidator
func (*InterfaceValidator) Validate ¶
func (v *InterfaceValidator) Validate(value interface{}) (interface{}, error)
type LossyUint64Validator ¶
func LossyUint64 ¶
func LossyUint64() *LossyUint64Validator
Validate numbers as a uint64. In this process they will be stored as a float64, which can lead to a loss of precision as high as 1024(?).
func (*LossyUint64Validator) Max ¶
func (v *LossyUint64Validator) Max(max uint64)
func (*LossyUint64Validator) Min ¶
func (v *LossyUint64Validator) Min(min uint64)
func (*LossyUint64Validator) Validate ¶
func (v *LossyUint64Validator) Validate(value interface{}) (interface{}, error)
type MappedField ¶
type MultiValidationError ¶
type MultiValidationError struct {
NestedErrors []*FlattenedPathError
}
func (*MultiValidationError) AddError ¶
func (e *MultiValidationError) AddError(err *ValidationError, path ...string)
func (*MultiValidationError) Error ¶
func (e *MultiValidationError) Error() string
func (*MultiValidationError) Errors ¶
func (e *MultiValidationError) Errors() []*FlattenedPathError
type ParameterMap ¶
type ParameterMap struct { StructFieldName string ParameterName string Mapper QueryParameterMapper OmitEmpty bool }
ParameterMap corresponds to each field in a specific struct, it requires struct's name and the corresponding key value in the URL query
type PrimitiveMap ¶
type PrimitiveMap struct { V Validator // contains filtered or unexported fields }
type QueryMap ¶
type QueryMap struct { UnderlyingType interface{} ParameterMaps []ParameterMap }
This is the overarching struct used to transform structs into url params and vice versa
func (QueryMap) Decode ¶
Taking a URL Query (or any string->[]string struct) and shoving it into the struct as specified by qm.UnderlyingType
func (QueryMap) DecodeHeader ¶
type QueryParameterMapper ¶
type QueryParameterMapper interface { Encode(reflect.Value) ([]string, error) Decode(...string) (interface{}, error) }
QueryParameterMapper defines how url.Values value ([]string) and struct are to be transformed into each other. It is from a slice of strings, reflecting the structure of url.Values. These can be specified by their type (whichever struct the Parameter mapper will be, and the restrictions defined on the type, defined by Validators slice below)
type RawMessage ¶
type RawMessage struct {
Data []byte
}
func (RawMessage) MarshalJSON ¶
func (rm RawMessage) MarshalJSON() ([]byte, error)
type RegisterableTypeMap ¶
type RenderInfo ¶
type RenderInfo struct { Context Context Parent interface{} Value interface{} }
type StrPointerQueryParameterMapper ¶
type StrPointerQueryParameterMapper struct {
UnderlyingQueryParameterMapper QueryParameterMapper
}
func (StrPointerQueryParameterMapper) Decode ¶
func (pqpm StrPointerQueryParameterMapper) Decode(src ...string) (interface{}, error)
type StrSliceQueryParameterMapper ¶
type StrSliceQueryParameterMapper struct { Validators []func([]string) bool UnderlyingQueryParameterMapper QueryParameterMapper }
func (StrSliceQueryParameterMapper) Decode ¶
func (sqpm StrSliceQueryParameterMapper) Decode(src ...string) (interface{}, error)
type StringQueryParameterMapper ¶
Examples of mappers
func (StringQueryParameterMapper) Decode ¶
func (sqpm StringQueryParameterMapper) Decode(src ...string) (interface{}, error)
type StringValidator ¶
func String ¶
func String(minLen int, maxLen int) *StringValidator
func (*StringValidator) Regex ¶
func (v *StringValidator) Regex(re *regexp.Regexp) *StringValidator
func (*StringValidator) RegexError ¶
func (v *StringValidator) RegexError(re *regexp.Regexp, errMsg string) *StringValidator
func (*StringValidator) Validate ¶
func (v *StringValidator) Validate(value interface{}) (interface{}, error)
func (*StringValidator) ValidateString ¶
func (v *StringValidator) ValidateString(s string) (string, error)
type StringsSliceMapper ¶
type StringsSliceMapper struct {
StringValidator *StringValidator
}
type StructMap ¶
type StructMap struct { UnderlyingType interface{} Fields []MappedField }
func (StructMap) GetUnderlyingType ¶
type TimeMap ¶
type TimeMap struct {
// contains filtered or unexported fields
}
type TimeQueryParameterMapper ¶
func (TimeQueryParameterMapper) Decode ¶
func (tqpm TimeQueryParameterMapper) Decode(src ...string) (interface{}, error)
type TypeMap ¶
type TypeMap interface { Unmarshal(ctx Context, parent *reflect.Value, partial interface{}, dstValue reflect.Value) error Marshal(ctx Context, parent *reflect.Value, field reflect.Value) (json.Marshaler, error) }
func NewPrimitiveMap ¶
func NewStringsSliceMapper ¶
func NewStringsSliceMapper(sv *StringValidator) TypeMap
Used for StringsArray, which has a "V" field containing []string. Optionally can take a string validator to apply to each entry.
func SliceOfMax ¶
func SliceOfMin ¶
func SliceOfRange ¶
type TypeMapper ¶
type TypeMapper struct {
// contains filtered or unexported fields
}
func NewTypeMapper ¶
func NewTypeMapper(maps ...RegisterableTypeMap) *TypeMapper
func (*TypeMapper) Marshal ¶
func (tm *TypeMapper) Marshal(ctx Context, src interface{}) ([]byte, error)
func (*TypeMapper) MarshalIndent ¶
func (tm *TypeMapper) MarshalIndent(ctx Context, src interface{}, prefix, indent string) ([]byte, error)
type UUIDStringValidator ¶
type UUIDStringValidator struct{}
func UUIDString ¶
func UUIDString() *UUIDStringValidator
func (*UUIDStringValidator) Validate ¶
func (v *UUIDStringValidator) Validate(value interface{}) (interface{}, error)
func (*UUIDStringValidator) ValidateString ¶
func (v *UUIDStringValidator) ValidateString(value string) (string, error)
type UintQueryParameterMapper ¶
func (UintQueryParameterMapper) Decode ¶
func (uqpm UintQueryParameterMapper) Decode(src ...string) (interface{}, error)
type ValidationError ¶
type ValidationError struct { Field string Message string NestedErrors []*ValidationError }
func NewValidationError ¶
func NewValidationError(reason string, a ...interface{}) *ValidationError
func NewValidationErrorWithField ¶
func NewValidationErrorWithField(field, message string) *ValidationError
func (*ValidationError) AddError ¶
func (e *ValidationError) AddError(err *ValidationError)
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) ErrorMessage ¶
func (e *ValidationError) ErrorMessage() string
func (*ValidationError) Flatten ¶
func (e *ValidationError) Flatten() *MultiValidationError
func (*ValidationError) SetField ¶
func (e *ValidationError) SetField(field string)
type Validator ¶
type Validator interface {
Validate(interface{}) (interface{}, error)
}