Documentation ¶
Overview ¶
Package validator wraps https://github.com/go-playground/validator to provide value validations for structs and individual fields based on tags. It includes a simpler custom translation mechanism for errors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CustomValidationTags ¶
CustomValidationTags returns a map of custom tags with validation function.
func ErrorTemplates ¶
ErrorTemplates returns a map of validation tags with error messages as html templates.
Types ¶
type Error ¶
type Error struct { // Tag is the validation tag that failed (e.g. "max"). Tag string // Param is the Tag's parameter value (if any - e.g. "10"). Param string // FullTag is the validation tag that failed with included parameters (e.g. "max=10"). FullTag string // Namespace for the field error, with the tag name taking precedence over the field's actual name. Namespace string // StructNamespace is the namespace for the field error, with the field's actual name. StructNamespace string // Field is the field name with the tag name taking precedence over the field's actual name. Field string // StructField is the field's actual name from the struct. StructField string // Kind is the Field's string representation of the kind (e.g. Int,Slice,...). Kind string // Value is the actual field's value. Value interface{} // Err is the translated error message. Err string }
Error is a custom error adding a Field member.
type Option ¶
Option is the interface that allows to set configuration options.
func WithCustomValidationTags ¶
WithCustomValidationTags register custom tags and validation functions.
func WithErrorTemplates ¶
WithErrorTemplates sets basic template-based error message translations. The argument t maps tags to html templates that uses the Error data. These translations takes precedence over the parent library translation object.
func WithFieldNameTag ¶
WithFieldNameTag allows to use the field names specified by the tag instead of the original struct names.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator contains the validator object fields.
func (*Validator) ValidateStruct ¶
ValidateStruct validates the structure fields tagged with "validate" and returns a multierror.