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 ¶
InvalidContentType creates new InvalidContentTypeError.
func UnexpectedStatusCode ¶
UnexpectedStatusCode creates new UnexpectedStatusCode.
func UniqueItems ¶
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 ¶
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 ¶
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 ¶
SetExclusiveMaximum sets exclusive maximum value.
func (*Float) SetExclusiveMinimum ¶
SetExclusiveMinimum sets exclusive minimum value.
func (*Float) SetMultipleOf ¶
SetMultipleOf sets multipleOf validator.
func (Float) ValidateStringified ¶
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 ¶
type InvalidContentTypeError struct {
ContentType string
}
InvalidContentTypeError reports that decoder got unexpected content type.
func (*InvalidContentTypeError) Error ¶
func (e *InvalidContentTypeError) Error() string
InvalidContentTypeError implements error.
type MaxLengthError ¶
MaxLengthError reports that len greater than maximum.
func (*MaxLengthError) Error ¶
func (e *MaxLengthError) Error() string
MaxLengthError implements error.
type MinLengthError ¶
MinLengthError reports that len less than minimum.
func (*MinLengthError) Error ¶
func (e *MinLengthError) Error() string
MinLengthError implements error.
type NoRegexMatchError ¶
type NoRegexMatchError struct{}
NoRegexMatchError reports that value have no regexp match.
func (*NoRegexMatchError) Error ¶
func (*NoRegexMatchError) Error() string
MaxLengthError implements error.
type Object ¶
type Object struct {
MinProperties int
MinPropertiesSet bool
MaxProperties int
MaxPropertiesSet bool
}
Object validates map length.
func (*Object) SetMaxProperties ¶
SetMaxProperties sets MaxProperties validation.
func (*Object) SetMinProperties ¶
SetMinProperties sets MinProperties validation.
func (Object) ValidateProperties ¶
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 ¶
type UnexpectedStatusCodeError struct {
StatusCode int
}
UnexpectedStatusCodeError reports that client got unexpected status code.
func (*UnexpectedStatusCodeError) Error ¶
func (e *UnexpectedStatusCodeError) Error() string
UnexpectedStatusCodeError implements error.