Documentation ¶
Overview ¶
Package valpar provides feature of request value parsing, handling, binding and validating.
Index ¶
- Variables
- func AddValueParser(typ reflect.Type, parser Parser) error
- func Body(contentType string, body io.Reader, typ reflect.Type) (reflect.Value, error)
- func Struct(key string, typ reflect.Type, params url.Values) (reflect.Value, error)
- func Validate(s interface{}) (validator.ValidationErrors, error)
- func ValidateValue(v interface{}, constraint string) bool
- func Validator() *validator.Validate
- type Error
- type Errors
- type Parser
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTypeOrParserIsNil returned when supplied `reflect.Type` or parser is nil to // the method `AddValueParser`. ErrTypeOrParserIsNil = errors.New("valpar: type or value parser is nil") // ErrValueParserIsAlreadyExists returned when given `reflect.Type` is already exists // in type parser list. ErrValueParserIsAlreadyExists = errors.New("valpar: value parser is already exists") // TimeFormats is configured values from aah.conf under `format { ... }` TimeFormats []string // StructTagName is used while binding struct fields. StructTagName string )
Functions ¶
func AddValueParser ¶
AddValueParser method adds given custom value parser for the `reflect.Type`
func Validate ¶
func Validate(s interface{}) (validator.ValidationErrors, error)
Validate method is to validate struct via underneath validator.
Returns:
For validation errors: returns `validator.ValidationErrors` and nil
For invalid input: returns nil, error (invalid input such as nil, non-struct, etc.)
For no validation errors: nil, nil
func ValidateValue ¶
ValidateValue method is to validate individual value. Returns true if validation is passed otherwise false.
For example:
i := 15 result := valpar.ValidateValue(i, "gt=1,lt=10") emailAddress := "sample@sample" result := valpar.ValidateValue(emailAddress, "email") numbers := []int{23, 67, 87, 23, 90} result := valpar.ValidateValue(numbers, "unique")
func Validator ¶
func Validator() *validator.Validate
Validator method return the default validator of aah framework.
Refer to https://godoc.org/gopkg.in/go-playground/validator.v9 for detailed documentation.
Types ¶
type Error ¶
type Error struct { Field string Value string Key string // i18n key Msg string // i18n message Constraint string }
Error represents single validation error details.
type Errors ¶
type Errors []*Error
Errors type represents list errors.
func ValidateValues ¶
ValidateValues method validates the values with respective constraints. Returns nil if no errors otherwise slice of error.