Documentation
¶
Overview ¶
Package validation provides additional validation rules built on top of ozzo-validation and its `is` helpers.
It extends the standard rule set with reusable and project-specific validators while remaining fully compatible with the ozzo-validation API.
Upstream projects:
- ozzo-validation: https://github.com/go-ozzo/ozzo-validation
- ozzo-validation/is: https://github.com/go-ozzo/ozzo-validation/tree/master/is
Documentation:
Index ¶
- Variables
- func NewAllRule(rule ...validation.Rule) validation.Rule
- func NewAllRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
- func NewAnyRule(rule ...validation.Rule) validation.Rule
- func NewAnyRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
- func NewNoneRule(rule ...validation.Rule) validation.Rule
- func NewNoneRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
- type ICompositeRule
Constants ¶
This section is empty.
Variables ¶
var IsBase64 = validation.NewStringRuleWithError(base64.IsEncoded, is.ErrBase64)
IsBase64 validates whether a value is a base64 encoded string. It is similar to is.Base64 but more generic and robust although less performant.
var IsPathParameter = validation.NewStringRule(isValidPathParameter, "invalid path parameter")
IsPathParameter validates whether a value is a valid path parameter of a url.
var IsPort = validation.By(isPort)
IsPort validates whether a value is a port using is.Port from github.com/go-ozzo/ozzo-validation/v4. However, it supports all base go integer types not just strings.
Functions ¶
func NewAllRule ¶ added in v1.153.0
func NewAllRule(rule ...validation.Rule) validation.Rule
NewAllRule returns a rule that succeeds only if all of the provided rules succeed.
This is equivalent to grouping the same rules under validation.Validate.
func NewAllRuleWithContext ¶ added in v1.153.0
func NewAllRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
NewAllRuleWithContext returns a context-aware rule that succeeds only if all of the provided context-aware rules succeed.
This is equivalent to grouping the same rules under validation.ValidateWithContext.
func NewAnyRule ¶ added in v1.153.0
func NewAnyRule(rule ...validation.Rule) validation.Rule
NewAnyRule returns a rule that succeeds if at least one of the provided rules succeeds.
This complements validation.Validate, where multiple rules are normally combined with AND semantics.
func NewAnyRuleWithContext ¶ added in v1.153.0
func NewAnyRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
NewAnyRuleWithContext returns a context-aware rule that succeeds if at least one of the provided context-aware rules succeeds.
This complements validation.Validate and validation.ValidateWithContext, where multiple rules are normally combined with AND semantics.
func NewNoneRule ¶ added in v1.153.0
func NewNoneRule(rule ...validation.Rule) validation.Rule
NewNoneRule returns a rule that succeeds only if none of the provided rules succeed.
This is useful when a value must not match any rule in a given set.
func NewNoneRuleWithContext ¶ added in v1.153.0
func NewNoneRuleWithContext(rule ...validation.RuleWithContext) validation.RuleWithContext
NewNoneRuleWithContext returns a context-aware rule that succeeds only if none of the provided context-aware rules succeed.
Types ¶
type ICompositeRule ¶ added in v1.153.0
type ICompositeRule interface {
// AppendRule adds one or more non-contextual rules to the composite rule.
AppendRule(rule ...validation.Rule)
// AppendContextualRule adds one or more context-aware rules to the
// composite rule.
AppendContextualRule(rule ...validation.RuleWithContext)
validation.Rule
validation.RuleWithContext
}
ICompositeRule represents a mutable logical rule set.
A ICompositeRule can combine both standard ozzo rules and context-aware rules, and can itself be used anywhere a validation.Rule or validation.RuleWithContext is accepted, including with validation.Validate.
func NewAllCompositeRule ¶ added in v1.153.0
func NewAllCompositeRule() ICompositeRule
NewAllCompositeRule returns an empty composite rule with AND semantics.
The returned rule succeeds only if all appended rules succeed, matching the behaviour of validation.Validate.
func NewAnyCompositeRule ¶ added in v1.153.0
func NewAnyCompositeRule() ICompositeRule
NewAnyCompositeRule returns an empty composite rule with OR semantics.
The returned rule succeeds if at least one appended rule succeeds, unlike validation.Validate which requires all supplied rules to succeed.
func NewNoneCompositeRule ¶ added in v1.153.0
func NewNoneCompositeRule() ICompositeRule
NewNoneCompositeRule returns an empty composite rule with NONE semantics.
The returned rule succeeds only if none of the appended rules succeed.