Documentation
¶
Overview ¶
Package validator contains Validator service singleton. It can be used in a custom application to perform the validation process.
Index ¶
- func AtIndex(index int) *validation.Validator
- func AtProperty(name string) *validation.Validator
- func BuildViolation(ctx context.Context, code, message string) *validation.ViolationBuilder
- func Reset()
- func SetOptions(options ...validation.ValidatorOption) error
- func Validate(ctx context.Context, arguments ...validation.Argument) error
- func ValidateBool(ctx context.Context, value bool, options ...validation.Option) error
- func ValidateBy(constraintKey string) validation.Constraint
- func ValidateCountable(ctx context.Context, count int, options ...validation.Option) error
- func ValidateEach(ctx context.Context, value interface{}, options ...validation.Option) error
- func ValidateEachString(ctx context.Context, strings []string, options ...validation.Option) error
- func ValidateIterable(ctx context.Context, value interface{}, options ...validation.Option) error
- func ValidateNumber(ctx context.Context, value interface{}, options ...validation.Option) error
- func ValidateString(ctx context.Context, value string, options ...validation.Option) error
- func ValidateStrings(ctx context.Context, values []string, options ...validation.Option) error
- func ValidateTime(ctx context.Context, value time.Time, options ...validation.Option) error
- func ValidateValidatable(ctx context.Context, validatable validation.Validatable, ...) error
- func ValidateValue(ctx context.Context, value interface{}, options ...validation.Option) error
- func WithLanguage(tag language.Tag) *validation.Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtIndex ¶
func AtIndex(index int) *validation.Validator
AtIndex method creates a new scoped validator with injected array index element to scope property path.
func AtProperty ¶
func AtProperty(name string) *validation.Validator
AtProperty method creates a new scoped validator with injected property name element to scope property path.
func BuildViolation ¶
func BuildViolation(ctx context.Context, code, message string) *validation.ViolationBuilder
BuildViolation can be used to build a custom violation on the client-side.
Example
err := validator.BuildViolation(context.Background(), "", ""). AddParameter("key", "value"). CreateViolation()
func Reset ¶
func Reset()
Reset function recreates singleton validator. Generally, it can be used in tests.
func SetOptions ¶
func SetOptions(options ...validation.ValidatorOption) error
SetOptions can be used to set up a singleton validator. Make sure you call this function once at the initialization of your application.
func Validate ¶
func Validate(ctx context.Context, arguments ...validation.Argument) error
Validate is the main validation method. It accepts validation arguments. Arguments can be used to tune up the validation process or to pass values of a specific type.
func ValidateBool ¶
ValidateBool is an alias for validating a single boolean value.
func ValidateBy ¶
func ValidateBy(constraintKey string) validation.Constraint
ValidateBy is used to get the constraint from the internal validator store. If the constraint does not exist, then the validator will return a ConstraintNotFoundError during the validation process. For storing a constraint you should use the validation.StoredConstraint option.
func ValidateCountable ¶
ValidateCountable is an alias for validating a single countable value (an array, slice, or map).
func ValidateEach ¶
func ValidateEach(ctx context.Context, value interface{}, options ...validation.Option) error
ValidateEach is an alias for validating each value of an iterable (an array, slice, or map).
func ValidateEachString ¶
ValidateEachString is an alias for validating each value of a strings slice.
func ValidateIterable ¶
func ValidateIterable(ctx context.Context, value interface{}, options ...validation.Option) error
ValidateIterable is an alias for validating a single iterable value (an array, slice, or map).
func ValidateNumber ¶
func ValidateNumber(ctx context.Context, value interface{}, options ...validation.Option) error
ValidateNumber is an alias for validating a single numeric value (integer or float).
func ValidateString ¶
ValidateString is an alias for validating a single string value.
func ValidateStrings ¶ added in v0.4.0
ValidateStrings is an alias for validating slice of strings.
func ValidateTime ¶
ValidateTime is an alias for validating a single time value.
func ValidateValidatable ¶
func ValidateValidatable(ctx context.Context, validatable validation.Validatable, options ...validation.Option) error
ValidateValidatable is an alias for validating value that implements the Validatable interface.
func ValidateValue ¶
func ValidateValue(ctx context.Context, value interface{}, options ...validation.Option) error
ValidateValue is an alias for validating a single value of any supported type.
func WithLanguage ¶
func WithLanguage(tag language.Tag) *validation.Validator
WithLanguage method creates a new scoped validator with a given language tag. All created violations will be translated into this language.
Example
err := validator.WithLanguage(language.Russian).Validate( validation.ValidateString(&s, it.IsNotBlank()), // violation from this constraint will be translated )
Types ¶
This section is empty.