A struct validator which group in a map and custom errors messages from a simplified Go Validator.
validate.RegisterValidation("underAge", underAge, "the :field is too low")
// name is the validation name where will be used on struct tags
// function is the validation function that will receive the field
// value to be validate
// message is the custom message when validation failed, use :field
// in the message and will be replaced by failed field name
validate.RegisterValidation(name string, function ValidationFunc, message string)
type ValidationFunc func(field IField) bool
type IField interface {
Field() reflect.Value
}
type Student struct {
Name string `validate:"required"`
Email string `validate:"required,email"`
Password string `validate:"required"`
Age int `validate:"underAge"`
}
validate.RegisterValidationMessage("underAge", "the :field is too low")
validate.RegisterValidationMessage(name string, message string)
// data is struct that will be under validation
// errors is a map[string]string with the failed field
// name as key and error message as value
// ok is a boolean warning the validation status
errors, ok := validate.Validate(data interface{})