Documentation ¶
Overview ¶
Package validate contains validation helpers.
Index ¶
- Variables
- func InvalidContentType(contentType string) error
- func UnexpectedStatusCode(statusCode int) error
- func UniqueItems[S ~[]T, T comparable](arr S) error
- type Array
- type Error
- type FieldError
- type Float
- func (t Float) Set() bool
- func (t *Float) SetExclusiveMaximum(v float64)
- func (t *Float) SetExclusiveMinimum(v float64)
- func (t *Float) SetMaximum(v float64)
- func (t *Float) SetMinimum(v float64)
- func (t *Float) SetMultipleOf(rat *big.Rat)
- func (t Float) Validate(v float64) error
- func (t Float) ValidateStringified(v float64) error
- type Int
- type InvalidContentTypeError
- type MaxLengthError
- type MinLengthError
- type NoRegexMatchError
- type Object
- type String
- type UnexpectedStatusCodeError
Constants ¶
This section is empty.
Variables ¶
var ErrBodyRequired = errors.New("body required")
ErrBodyRequired reports that request body is required but server got empty request.
var ErrFieldRequired = errors.New("field required")
ErrFieldRequired reports that field is required, but not found.
var ErrNilPointer = errors.New("nil pointer")
ErrNilPointer reports that use Validate, but receiver pointer is nil.
Functions ¶
func InvalidContentType ¶ added in v0.11.1
InvalidContentType creates new InvalidContentTypeError.
func UnexpectedStatusCode ¶ added in v0.11.1
UnexpectedStatusCode creates new UnexpectedStatusCode.
func UniqueItems ¶ added in v0.67.0
func UniqueItems[S ~[]T, T comparable](arr S) error
UniqueItems ensures given array has no duplicates.
Types ¶
type Array ¶
type Array struct { MinLength int MinLengthSet bool MaxLength int MaxLengthSet bool UniqueItems bool }
Array validates array length.
func (*Array) SetMaxLength ¶
SetMaxLength sets MaxLength validation.
func (*Array) SetMinLength ¶
SetMinLength sets MinLength validation.
func (*Array) SetUniqueItems ¶ added in v0.67.0
SetUniqueItems sets UniqueItems validation.
func (Array) ValidateLength ¶
ValidateLength returns error if array length v is invalid.
type FieldError ¶
FieldError is failed validation on field.
type Float ¶ added in v0.16.0
type Float struct { MultipleOf *big.Rat MultipleOfSet bool Min float64 MinSet bool MinExclusive bool Max float64 MaxSet bool MaxExclusive bool }
Float validates float numbers.
func (*Float) SetExclusiveMaximum ¶ added in v0.16.0
SetExclusiveMaximum sets exclusive maximum value.
func (*Float) SetExclusiveMinimum ¶ added in v0.16.0
SetExclusiveMinimum sets exclusive minimum value.
func (*Float) SetMaximum ¶ added in v0.16.0
SetMaximum sets maximum value.
func (*Float) SetMinimum ¶ added in v0.16.0
SetMinimum sets minimum value.
func (*Float) SetMultipleOf ¶ added in v0.16.0
SetMultipleOf sets multipleOf validator.
func (Float) Validate ¶ added in v0.16.0
Validate returns error if v does not match validation rules.
func (Float) ValidateStringified ¶ added in v0.70.0
ValidateStringified returns error if v does not match validation rules.
type Int ¶
type Int struct { MultipleOf uint64 MultipleOfSet bool Min int64 MinSet bool MinExclusive bool Max int64 MaxSet bool MaxExclusive bool }
Int validates integers.
func (*Int) SetExclusiveMaximum ¶
SetExclusiveMaximum sets exclusive maximum value.
func (*Int) SetExclusiveMinimum ¶
SetExclusiveMinimum sets exclusive minimum value.
func (*Int) SetMultipleOf ¶
SetMultipleOf sets multipleOf validator.
type InvalidContentTypeError ¶ added in v0.11.1
type InvalidContentTypeError struct {
ContentType string
}
InvalidContentTypeError reports that decoder got unexpected content type.
func (*InvalidContentTypeError) Error ¶ added in v0.11.1
func (e *InvalidContentTypeError) Error() string
InvalidContentTypeError implements error.
type MaxLengthError ¶ added in v0.78.0
MaxLengthError reports that len greater than maximum.
func (*MaxLengthError) Error ¶ added in v0.78.0
func (e *MaxLengthError) Error() string
MaxLengthError implements error.
type MinLengthError ¶ added in v0.78.0
MinLengthError reports that len less than minimum.
func (*MinLengthError) Error ¶ added in v0.78.0
func (e *MinLengthError) Error() string
MinLengthError implements error.
type NoRegexMatchError ¶ added in v0.79.0
NoRegexMatchError reports that value have no regexp match.
func (*NoRegexMatchError) Error ¶ added in v0.79.0
func (e *NoRegexMatchError) Error() string
MaxLengthError implements error.
type Object ¶ added in v0.12.0
type Object struct { MinProperties int MinPropertiesSet bool MaxProperties int MaxPropertiesSet bool }
Object validates map length.
func (*Object) SetMaxProperties ¶ added in v0.12.0
SetMaxProperties sets MaxProperties validation.
func (*Object) SetMinProperties ¶ added in v0.12.0
SetMinProperties sets MinProperties validation.
func (Object) ValidateProperties ¶ added in v0.12.0
ValidateProperties returns error if object length (properties number) v is invalid.
type String ¶
type String struct { MinLength int MinLengthSet bool MaxLength int MaxLengthSet bool Email bool Regex ogenregex.Regexp Hostname bool }
String validator.
func (*String) SetMaxLength ¶
SetMaxLength sets maximum string length (in Unicode code points).
func (*String) SetMinLength ¶
SetMinLength sets minimum string length (in Unicode code points).
type UnexpectedStatusCodeError ¶ added in v0.11.1
type UnexpectedStatusCodeError struct {
StatusCode int
}
UnexpectedStatusCodeError reports that client got unexpected status code.
func (*UnexpectedStatusCodeError) Error ¶ added in v0.11.1
func (e *UnexpectedStatusCodeError) Error() string
UnexpectedStatusCodeError implements error.