Documentation
¶
Overview ¶
Package validate provides Runa validate primitives.
Index ¶
- func Invalid(items ...FieldError) error
- type Field
- func (field *Field) Call(handler any) *Field
- func (field *Field) Email(message string) *Field
- func (field *Field) Max(max float64, message string) *Field
- func (field *Field) MaxLen(max int, message string) *Field
- func (field *Field) Min(min float64, message string) *Field
- func (field *Field) MinLen(min int, message string) *Field
- func (field *Field) Regex(pattern string, message string) *Field
- func (field *Field) Required(message string) *Field
- func (field *Field) Value(value any) *Field
- type FieldError
- type FieldSchema
- type ValidationError
- func (err *ValidationError) Error() string
- func (err *ValidationError) ErrorCode() string
- func (err *ValidationError) ErrorFields() []FieldError
- func (err *ValidationError) ErrorMessage() string
- func (err *ValidationError) ErrorParams() core.Map
- func (err *ValidationError) ErrorStatus() int
- func (err *ValidationError) Unwrap() error
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field defines validation rules for one field.
type FieldError ¶
type FieldError struct {
Source string
Field string
Name string
Code string
Message string
Params core.Map
}
FieldError describes a single validation field error.
type FieldSchema ¶
type FieldSchema struct {
Source string
Name string
Field string
Label string
Description string
Default string
Type string
Format string
}
FieldSchema stores input field metadata collected from struct tags.
type ValidationError ¶
type ValidationError struct {
Errors []FieldError
Cause error
}
ValidationError describes validation errors.
func AsError ¶
func AsError(err error) *ValidationError
AsError returns a ValidationError when err contains one.
func (*ValidationError) Error ¶
func (err *ValidationError) Error() string
Error returns the first field error message or a default message.
func (*ValidationError) ErrorCode ¶
func (err *ValidationError) ErrorCode() string
ErrorCode returns the standard error code.
func (*ValidationError) ErrorFields ¶
func (err *ValidationError) ErrorFields() []FieldError
ErrorFields returns validation field errors for renderers.
func (*ValidationError) ErrorMessage ¶
func (err *ValidationError) ErrorMessage() string
ErrorMessage returns the public error message.
func (*ValidationError) ErrorParams ¶
func (err *ValidationError) ErrorParams() core.Map
ErrorParams returns translation/rendering parameters for the first field error.
func (*ValidationError) ErrorStatus ¶
func (err *ValidationError) ErrorStatus() int
ErrorStatus returns the HTTP status.
func (*ValidationError) Unwrap ¶
func (err *ValidationError) Unwrap() error
Unwrap returns the cause error.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates a bound input or an explicit value set.
func (*Validator) AddError ¶
func (validator *Validator) AddError(item FieldError)
AddError adds a field error.