Documentation
¶
Index ¶
- Variables
- func MustValidate(m Fields) bool
- type FieldError
- type Fields
- type Validator
- func (v *Validator) AddError(field string, msg string)
- func (v *Validator) AddErrorf(field string, msg string)
- func (v *Validator) AddPlainError(field string, msg string)
- func (v *Validator) AddRawError(field string, label string, msg string)
- func (v *Validator) ComponentID() string
- func (v *Validator) Errors() []*FieldError
- func (v *Validator) GetFieldLabel(field string) string
- func (v *Validator) HasError() bool
- func (v *Validator) Validate() error
- func (v *Validator) ValidateField(validated bool, field string, msg string)
- func (v *Validator) ValidateFieldMessagef(validated bool, field string, msg ui.Translatable)
- func (v *Validator) ValidateFieldf(validated bool, field string, msg string)
Constants ¶
This section is empty.
Variables ¶
var ErrNoValidateMethod = errors.New("error no validate method for model")
ErrNoValidateMethod error rasied when model validate method not overrided.
Functions ¶
func MustValidate ¶
MustValidate return model validate result. Panic if any error raised.
Types ¶
type FieldError ¶
type FieldError struct { //Field field name. Field string //Label field label. //If field not found in model's labels,field label is same as field name. Label string //Msg error message Msg string }
FieldError field error info struct
type Fields ¶
type Fields interface { ui.TranslationLanguage ui.Component ui.ComponentLabels //HasError return if model has any error. HasError() bool //Errors return error list of model Errors() []*FieldError //AddError add error by given field and plain msg. AddError(field string, msg string) //AddErrorf add error by given field and formatted msg. AddErrorf(field string, msg string) //Validate method used to validate model. //Fail validation will add error to model. //Return any error if rasied. Validate() error //GetFieldLabel get label by given label name. GetFieldLabel(field string) string }
Fields interface for model that can be validated.
type Validator ¶
type Validator struct { ui.Language ui.LabelsComponent // contains filtered or unexported fields }
Validator model struct.
func (*Validator) AddError ¶
AddError add error by given field and plain msg. Msg will be translated.
func (*Validator) AddErrorf ¶
AddErrorf add error by given field and formatted msg. Msg will be translated.
func (*Validator) AddPlainError ¶
AddPlainError add plain error with given field and msg. Msg will not be translated.
func (*Validator) AddRawError ¶
func (*Validator) ComponentID ¶
ComponentID get ui component id
func (*Validator) Errors ¶
func (v *Validator) Errors() []*FieldError
Errors return error list of model
func (*Validator) GetFieldLabel ¶
GetFieldLabel get label by given label name. Return field name itself if not found in field labels of model.
func (*Validator) Validate ¶
Validate method used to validate model. Fail validation will add error to model. Return any error if rasied. You must override this method for your own model,otherwise ErrNoValidateMethod will be raised.
func (*Validator) ValidateField ¶
ValidateField validated field then add error with given field name and plain msg if not validated.
func (*Validator) ValidateFieldMessagef ¶
func (v *Validator) ValidateFieldMessagef(validated bool, field string, msg ui.Translatable)
ValidateFieldMessagef validated field then add error with given field name and string interfcae msg if not validated.