Documentation ¶
Overview ¶
Package validator contains Validator service singleton. It can be used in a custom application to perform the validation process.
Index ¶
- func At(path ...validation.PropertyPathElement) *validation.Validator
- func AtIndex(index int) *validation.Validator
- func AtProperty(name string) *validation.Validator
- func BuildViolation(ctx context.Context, err error, message string) *validation.ViolationBuilder
- func BuildViolationList(ctx context.Context) *validation.ViolationListBuilder
- func CreateViolation(ctx context.Context, err error, message string, ...) validation.Violation
- func Instance() *validation.Validator
- func SetUp(options ...validation.ValidatorOption) error
- func Validate(ctx context.Context, arguments ...validation.Argument) error
- func ValidateBool(ctx context.Context, value bool, constraints ...validation.BoolConstraint) error
- func ValidateCountable(ctx context.Context, count int, constraints ...validation.CountableConstraint) error
- func ValidateEachString(ctx context.Context, strings []string, ...) error
- func ValidateFloat(ctx context.Context, value float64, ...) error
- func ValidateInt(ctx context.Context, value int, ...) error
- func ValidateIt(ctx context.Context, validatable validation.Validatable) error
- func ValidateString(ctx context.Context, value string, constraints ...validation.StringConstraint) error
- func ValidateStrings(ctx context.Context, values []string, ...) error
- func ValidateTime(ctx context.Context, value time.Time, constraints ...validation.TimeConstraint) error
- func WithGroups(groups ...string) *validation.Validator
- func WithLanguage(tag language.Tag) *validation.Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func At ¶ added in v0.13.0
func At(path ...validation.PropertyPathElement) *validation.Validator
At method creates a new context validator with appended property path.
func AtIndex ¶
func AtIndex(index int) *validation.Validator
AtIndex method creates a new context validator with appended array index to the property path.
func AtProperty ¶
func AtProperty(name string) *validation.Validator
AtProperty method creates a new context validator with appended property name to the property path.
func BuildViolation ¶
func BuildViolation(ctx context.Context, err error, message string) *validation.ViolationBuilder
BuildViolation can be used to build a custom violation on the client-side.
func BuildViolationList ¶ added in v0.11.0
func BuildViolationList(ctx context.Context) *validation.ViolationListBuilder
BuildViolationList can be used to build a custom violation list on the client-side.
func CreateViolation ¶ added in v0.11.0
func CreateViolation(ctx context.Context, err error, message string, path ...validation.PropertyPathElement) validation.Violation
CreateViolation can be used to quickly create a custom violation on the client-side.
func Instance ¶ added in v0.16.0
func Instance() *validation.Validator
Instance returns the instance of the singleton validator.
func SetUp ¶ added in v0.6.0
func SetUp(options ...validation.ValidatorOption) error
SetUp can be used to set up a new instance of singleton validator. Make sure you call this function once at the initialization of your application because it totally replaces validator instance.
func Validate ¶
func Validate(ctx context.Context, arguments ...validation.Argument) error
Validate is the main validation method. It accepts validation arguments. executionContext can be used to tune up the validation process or to pass values of a specific type.
func ValidateBool ¶
func ValidateBool(ctx context.Context, value bool, constraints ...validation.BoolConstraint) error
ValidateBool is an alias for validating a single boolean value.
func ValidateCountable ¶
func ValidateCountable(ctx context.Context, count int, constraints ...validation.CountableConstraint) error
ValidateCountable is an alias for validating a single countable value (an array, slice, or map).
func ValidateEachString ¶
func ValidateEachString(ctx context.Context, strings []string, constraints ...validation.StringConstraint) error
ValidateEachString is an alias for validating each value of a strings slice.
func ValidateFloat ¶ added in v0.9.0
func ValidateFloat(ctx context.Context, value float64, constraints ...validation.NumberConstraint[float64]) error
ValidateFloat is an alias for validating a single float value.
func ValidateInt ¶ added in v0.9.0
func ValidateInt(ctx context.Context, value int, constraints ...validation.NumberConstraint[int]) error
ValidateInt is an alias for validating a single integer value.
func ValidateIt ¶ added in v0.9.0
func ValidateIt(ctx context.Context, validatable validation.Validatable) error
ValidateIt is an alias for validating value that implements the Validatable interface.
func ValidateString ¶
func ValidateString(ctx context.Context, value string, constraints ...validation.StringConstraint) error
ValidateString is an alias for validating a single string value.
func ValidateStrings ¶ added in v0.4.0
func ValidateStrings(ctx context.Context, values []string, constraints ...validation.ComparablesConstraint[string]) error
ValidateStrings is an alias for validating slice of strings.
func ValidateTime ¶
func ValidateTime(ctx context.Context, value time.Time, constraints ...validation.TimeConstraint) error
ValidateTime is an alias for validating a single time value.
func WithGroups ¶ added in v0.8.0
func WithGroups(groups ...string) *validation.Validator
WithGroups is used to execute conditional validation based on validation groups. It creates a new context validator with a given set of groups.
By default, when validating an object all constraints of it will be checked whether or not they pass. In some cases, however, you will need to validate an object against only some specific group of constraints. To do this, you can organize each constraint into one or more validation groups and then apply validation against one group of constraints.
Validation groups are working together only with validation groups passed to a constraint by WhenGroups() method. This method is implemented in all built-in constraints. If you want to use validation groups for your own constraints do not forget to implement this method in your constraint.
Be careful, empty groups are considered as the default group. Its value is equal to the validation.DefaultGroup ("default").
func WithLanguage ¶
func WithLanguage(tag language.Tag) *validation.Validator
WithLanguage method creates a new context validator with a given language tag. All created violations will be translated into this language.
Types ¶
This section is empty.