validateruntime

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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.

View Source
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

func IsEmail(s string) bool

IsEmail reports whether s is a valid email address. Delegates to EmailValidator, which defaults to a pre-compiled regex.

func IsURI

func IsURI(s string) bool

IsURI reports whether s is a valid URI (RFC 3986). Delegates to URIValidator, which defaults to net/url.ParseRequestURI.

func MatchPattern

func MatchPattern(s, pattern string) bool

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.

func MsgOr

func MsgOr(override, defaultMsg string) string

MsgOr returns override if non-empty, otherwise defaultMsg. Used by generated Validate() methods to apply per-field message overrides.

Types

type ValidationError

type ValidationError struct {
	Field   string
	Rule    string
	Message string
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL