Documentation ¶
Overview ¶
Package xvalid is a lightweight validation library that can export rules as JSON so browsers can apply the same rules.
Index ¶
- func IsEmail(email string) bool
- type EmailValidator
- func (c *EmailValidator) CanExport() bool
- func (c *EmailValidator) Field() []string
- func (c *EmailValidator) MarshalJSON() ([]byte, error)
- func (c *EmailValidator) SetField(name ...string)
- func (c *EmailValidator) SetMessage(msg string) Validator
- func (c *EmailValidator) SetOptional() Validator
- func (c *EmailValidator) Validate(value any) Error
- type Error
- type ErrorMap
- type ErrorSlice
- type FieldFuncValidator
- type MaxLengthValidator
- func (c *MaxLengthValidator) CanExport() bool
- func (c *MaxLengthValidator) Field() []string
- func (c *MaxLengthValidator) MarshalJSON() ([]byte, error)
- func (c *MaxLengthValidator) SetField(name ...string)
- func (c *MaxLengthValidator) SetMessage(msg string) Validator
- func (c *MaxLengthValidator) Validate(value any) Error
- type MaxValidator
- type MinLengthValidator
- func (c *MinLengthValidator) CanExport() bool
- func (c *MinLengthValidator) Field() []string
- func (c *MinLengthValidator) MarshalJSON() ([]byte, error)
- func (c *MinLengthValidator) SetField(name ...string)
- func (c *MinLengthValidator) SetMessage(msg string) Validator
- func (c *MinLengthValidator) SetOptional() Validator
- func (c *MinLengthValidator) Validate(value any) Error
- type MinValidator
- func (c *MinValidator) CanExport() bool
- func (c *MinValidator) Field() []string
- func (c *MinValidator) MarshalJSON() ([]byte, error)
- func (c *MinValidator) SetField(name ...string)
- func (c *MinValidator) SetMessage(msg string) Validator
- func (c *MinValidator) SetOptional() Validator
- func (c *MinValidator) Validate(value any) Error
- type OptionsValidator
- func (c *OptionsValidator) CanExport() bool
- func (c *OptionsValidator) Field() []string
- func (c *OptionsValidator) MarshalJSON() ([]byte, error)
- func (c *OptionsValidator) SetField(name ...string)
- func (c *OptionsValidator) SetMessage(msg string) Validator
- func (c *OptionsValidator) Validate(value any) Error
- type PatternValidator
- func (c *PatternValidator) CanExport() bool
- func (c *PatternValidator) Field() []string
- func (c *PatternValidator) MarshalJSON() ([]byte, error)
- func (c *PatternValidator) SetField(name ...string)
- func (c *PatternValidator) SetMessage(msg string) Validator
- func (c *PatternValidator) SetOptional() Validator
- func (c *PatternValidator) Validate(value any) Error
- type RequiredValidator
- func (c *RequiredValidator) CanExport() bool
- func (c *RequiredValidator) Field() []string
- func (c *RequiredValidator) MarshalJSON() ([]byte, error)
- func (c *RequiredValidator) SetField(field ...string)
- func (c *RequiredValidator) SetMessage(msg string) Validator
- func (c *RequiredValidator) Validate(value any) Error
- type Rules
- type StructFuncValidator
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type EmailValidator ¶
type EmailValidator struct { Validator // contains filtered or unexported fields }
EmailValidator field must be a valid email address
func (*EmailValidator) CanExport ¶
func (c *EmailValidator) CanExport() bool
CanExport for this validator
func (*EmailValidator) MarshalJSON ¶
func (c *EmailValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*EmailValidator) SetField ¶
func (c *EmailValidator) SetField(name ...string)
SetField of the field
func (*EmailValidator) SetMessage ¶
func (c *EmailValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*EmailValidator) SetOptional ¶
func (c *EmailValidator) SetOptional() Validator
SetOptional don't validate if the value is zero
func (*EmailValidator) Validate ¶
func (c *EmailValidator) Validate(value any) Error
Validate the value
type ErrorMap ¶
ErrorMap is a map of Error
type ErrorSlice ¶
type ErrorSlice []Error
ErrorSlice is a list of Error
func (ErrorSlice) Error ¶
func (e ErrorSlice) Error() string
Error will combine all errors into a list of sentences
type FieldFuncValidator ¶
type FieldFuncValidator struct {
// contains filtered or unexported fields
}
FieldFuncValidator for validating with custom function
func (*FieldFuncValidator) CanExport ¶
func (c *FieldFuncValidator) CanExport() bool
CanExport for this validator
func (*FieldFuncValidator) SetField ¶
func (c *FieldFuncValidator) SetField(name ...string)
SetField of the field
func (*FieldFuncValidator) SetMessage ¶
func (c *FieldFuncValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*FieldFuncValidator) Validate ¶
func (c *FieldFuncValidator) Validate(value any) Error
Validate the value
type MaxLengthValidator ¶
type MaxLengthValidator struct {
// contains filtered or unexported fields
}
MaxLengthValidator field have maximum length
func (*MaxLengthValidator) CanExport ¶
func (c *MaxLengthValidator) CanExport() bool
CanExport for this validator
func (*MaxLengthValidator) MarshalJSON ¶
func (c *MaxLengthValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MaxLengthValidator) SetField ¶
func (c *MaxLengthValidator) SetField(name ...string)
SetField of the field
func (*MaxLengthValidator) SetMessage ¶
func (c *MaxLengthValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MaxLengthValidator) Validate ¶
func (c *MaxLengthValidator) Validate(value any) Error
Validate the value
type MaxValidator ¶
type MaxValidator struct {
// contains filtered or unexported fields
}
MaxValidator field have maximum value
func (*MaxValidator) CanExport ¶
func (c *MaxValidator) CanExport() bool
CanExport for this validator
func (*MaxValidator) MarshalJSON ¶
func (c *MaxValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MaxValidator) SetField ¶
func (c *MaxValidator) SetField(name ...string)
SetField of the field
func (*MaxValidator) SetMessage ¶
func (c *MaxValidator) SetMessage(msg string) Validator
SetMessage set error message
type MinLengthValidator ¶
type MinLengthValidator struct {
// contains filtered or unexported fields
}
MinLengthValidator field must have minimum length
func MinLength ¶
func MinLength(min int64) *MinLengthValidator
MinLength field must have minimum length
func (*MinLengthValidator) CanExport ¶
func (c *MinLengthValidator) CanExport() bool
CanExport for this validator
func (*MinLengthValidator) MarshalJSON ¶
func (c *MinLengthValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MinLengthValidator) SetField ¶
func (c *MinLengthValidator) SetField(name ...string)
SetField of the field
func (*MinLengthValidator) SetMessage ¶
func (c *MinLengthValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MinLengthValidator) SetOptional ¶
func (c *MinLengthValidator) SetOptional() Validator
SetOptional don't validate if the value is zero
func (*MinLengthValidator) Validate ¶
func (c *MinLengthValidator) Validate(value any) Error
Validate the value
type MinValidator ¶
type MinValidator struct {
// contains filtered or unexported fields
}
MinValidator field have minimum value
func (*MinValidator) CanExport ¶
func (c *MinValidator) CanExport() bool
CanExport for this validator
func (*MinValidator) MarshalJSON ¶
func (c *MinValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*MinValidator) SetField ¶
func (c *MinValidator) SetField(name ...string)
SetField of the field
func (*MinValidator) SetMessage ¶
func (c *MinValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*MinValidator) SetOptional ¶
func (c *MinValidator) SetOptional() Validator
SetOptional don't validate if the value is zero
type OptionsValidator ¶
type OptionsValidator struct {
// contains filtered or unexported fields
}
OptionsValidator for whitelisting accepted values
func (*OptionsValidator) CanExport ¶
func (c *OptionsValidator) CanExport() bool
CanExport for this validator
func (*OptionsValidator) MarshalJSON ¶
func (c *OptionsValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*OptionsValidator) SetField ¶
func (c *OptionsValidator) SetField(name ...string)
SetField of the field
func (*OptionsValidator) SetMessage ¶
func (c *OptionsValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*OptionsValidator) Validate ¶
func (c *OptionsValidator) Validate(value any) Error
Validate the value
type PatternValidator ¶
type PatternValidator struct {
// contains filtered or unexported fields
}
PatternValidator field must match regexp
func (*PatternValidator) CanExport ¶
func (c *PatternValidator) CanExport() bool
CanExport for this validator
func (*PatternValidator) MarshalJSON ¶
func (c *PatternValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*PatternValidator) SetField ¶
func (c *PatternValidator) SetField(name ...string)
SetField of the field
func (*PatternValidator) SetMessage ¶
func (c *PatternValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*PatternValidator) SetOptional ¶
func (c *PatternValidator) SetOptional() Validator
SetOptional don't validate if the value is zero
func (*PatternValidator) Validate ¶
func (c *PatternValidator) Validate(value any) Error
Validate the value
type RequiredValidator ¶
type RequiredValidator struct {
// contains filtered or unexported fields
}
RequiredValidator field must not be zero
func (*RequiredValidator) CanExport ¶
func (c *RequiredValidator) CanExport() bool
CanExport for this validator
func (*RequiredValidator) MarshalJSON ¶
func (c *RequiredValidator) MarshalJSON() ([]byte, error)
MarshalJSON for this validator
func (*RequiredValidator) SetField ¶
func (c *RequiredValidator) SetField(field ...string)
SetField of the field
func (*RequiredValidator) SetMessage ¶
func (c *RequiredValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*RequiredValidator) Validate ¶
func (c *RequiredValidator) Validate(value any) Error
Validate the value
type Rules ¶
type Rules struct {
// contains filtered or unexported fields
}
Rules for creating a chain of rules for validating a struct
func (Rules) MarshalJSON ¶
func (Rules) Validate ¶
func (r Rules) Validate(subject any) ErrorSlice
Validate a struct and return Errors
type StructFuncValidator ¶
type StructFuncValidator struct {
// contains filtered or unexported fields
}
StructFuncValidator validate struct with custom function. Add to rules with .Struct().
func (*StructFuncValidator) CanExport ¶
func (c *StructFuncValidator) CanExport() bool
CanExport for this validator
func (*StructFuncValidator) Field ¶
func (c *StructFuncValidator) Field() []string
Field of the field
func (*StructFuncValidator) SetField ¶
func (c *StructFuncValidator) SetField(name ...string)
SetField of the field
func (*StructFuncValidator) SetMessage ¶
func (c *StructFuncValidator) SetMessage(msg string) Validator
SetMessage set error message
func (*StructFuncValidator) Validate ¶
func (c *StructFuncValidator) Validate(value any) Error
Validate the value
type Validator ¶
type Validator interface { SetField(...string) Field() []string CanExport() bool SetMessage(string) Validator Validate(any) Error }
Validator to implement a rule
func StructFunc ¶
StructFunc validate struct with custom function