Documentation
¶
Overview ¶
Package validateruntime provides runtime helpers for generated Validate() methods. It includes ValidationError (with Field/Rule/Message fields), email and URI validators, and a pattern-matching cache backed by sync.Map.
Package validateruntime provides runtime helpers for generated Validate() methods. It includes ValidationError, email/URI validators, and a pattern-matching cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EmailValidator = defaultIsEmail
EmailValidator is the function used by IsEmail. Replace it in init() to swap the email validation implementation. Replacement is only safe during program initialization (init functions run single-threaded before main). Concurrent replacement at runtime is not supported.
var URIValidator = defaultIsURI
URIValidator is the function used by IsURI. Replace it in init() to swap the URI validation implementation. Replacement is only safe during program initialization (init functions run single-threaded before main). Concurrent replacement at runtime is not supported.
Functions ¶
func IsEmail ¶
IsEmail reports whether s is a valid email address. Delegates to EmailValidator, which defaults to a pre-compiled regex.
func IsURI ¶
IsURI reports whether s is a valid URI (RFC 3986). Delegates to URIValidator, which defaults to net/url.ParseRequestURI.
func MatchPattern ¶
MatchPattern reports whether s matches the given regular expression pattern. Compiled regexps are cached in a package-level sync.Map; the pattern is guaranteed to be valid because the parser validates it at code-generation time.
Types ¶
type ValidationError ¶
ValidationError is returned by generated Validate() methods when a field fails a constraint. Field contains the full dot-separated path to the field (e.g. "address.city"), Rule names the constraint (e.g. "email", "min_len"), and Message is a human-readable description.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string