Documentation
¶
Overview ¶
Package validator provides simple, composable validation functions. Validators return nil on success and an error on failure. Use Validate to collect multiple validation results into a single slice.
Index ¶
- Constants
- func AgeRecipient(field, value string) error
- func Blank(field, value string) error
- func Email(field, value string) error
- func HTTPSURL(field, value string) error
- func JSONPath(field, value string) error
- func MaxLen(field, value string, max int) error
- func NoLeadingDot(field, value string) error
- func NotBlank(field, value string) error
- func OneOf(field, value string, allowed []string) error
- func PlainEmail(field, value string) error
- func Required[T comparable](field string, value T) error
- func RequiredSlice[T any](field string, values []T) error
- func TopicName(field, value string) error
- func UniqueStrings(field string, values []string) error
- func Validate(checks ...error) []error
Constants ¶
const MaxDescriptionLen = 128
MaxDescriptionLen is the maximum number of Unicode characters for a description field.
const MaxDisplayNameLen = 64
MaxDisplayNameLen is the maximum number of Unicode characters for a display name or short label.
Variables ¶
This section is empty.
Functions ¶
func AgeRecipient ¶
AgeRecipient returns an error if value is not a valid age X25519 recipient.
func Email ¶
Email returns an error if value is not a valid email address. It accepts general RFC-style addresses, including display-name forms such as `"Alice Example" <user@example.com>`. Use PlainEmail for login-style input.
func HTTPSURL ¶
HTTPSURL returns an error if value is not a valid HTTPS URL without private/internal IPs.
func JSONPath ¶
JSONPath returns an error unless value is a simple dot-separated path with optional numeric indexes.
func MaxLen ¶
MaxLen returns an error if value exceeds max Unicode characters (rune count, not byte length).
func NoLeadingDot ¶
NoLeadingDot returns an error if value begins with a dot after trimming whitespace.
func PlainEmail ¶
PlainEmail returns an error unless value is a plain email address with no display name. It is intended for login-style input such as `user@example.com`, not generic RFC address forms.
func Required ¶
func Required[T comparable](field string, value T) error
Required returns an error if value is the zero value for its type.
func RequiredSlice ¶
RequiredSlice returns an error if the slice is empty.
func UniqueStrings ¶
UniqueStrings returns an error if the slice contains duplicate string values.
Types ¶
This section is empty.