Documentation ¶
Overview ¶
Package validate implements validation functions, usually used RPC message validation.
Index ¶
- func All(fields ...error) error
- func Email(v interface{}) error
- func Empty(v interface{}) error
- func FieldMaskPaths(fm *types.FieldMask) error
- func In(slice interface{}) validateFn
- func MinLength(length int) validateFn
- func NotRequired(v interface{}) error
- func Password(v interface{}) error
- func Required(v interface{}) error
- type IsZeroer
- type ValidationField
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Email ¶
func Email(v interface{}) error
Email checks whether the input value is a valid email or not.
func Empty ¶
func Empty(v interface{}) error
Empty returns error if v is set. It is meant to be used as the first validator function passed as argument to Field. It uses IsZero, if v implements IsZeroer interface.
func FieldMaskPaths ¶
FieldMaskPaths performs a basic sanity check on the allowed characters for valid fieldmask paths. Paths of a FieldMask may only contain lowercase letters, numbers, dots, underscores and must be between 2 and 256 characters in length.
func In ¶
func In(slice interface{}) validateFn
In checks whether:
- an element is contained in an array or slice
- a slice is a subset of other slice
func MinLength ¶
func MinLength(length int) validateFn
MinLength checks whether the input value has a minimum length in the following cases:
- For strings checks the length
- For slices checks that aren't nil and its length
- For other types returns error
func NotRequired ¶
func NotRequired(v interface{}) error
NotRequired returns an error, used internally in Field, if v is zero. It is meant to be used as the first validator function passed as argument to Field. It uses IsZero, if v implements IsZeroer interface.
Types ¶
type IsZeroer ¶
type IsZeroer interface {
IsZero() bool
}
IsZeroer is an interface, which reports whether it represents a zero value.
type ValidationField ¶
type ValidationField struct {
// contains filtered or unexported fields
}
ValidationField implements error, and represents whether a field is valid or invalid.
func Field ¶
func Field(v interface{}, verifiers ...func(interface{}) error) (vf *ValidationField)
Field verifies whether a field is valid, and returns an error if it is invalid.
func (*ValidationField) DescribeFieldName ¶
func (vf *ValidationField) DescribeFieldName(name string) error
DescribeFieldName attaches the name of a field to the validation of a field, and returns it in an error format.