validator

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

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

View Source
const MaxDescriptionLen = 128

MaxDescriptionLen is the maximum number of Unicode characters for a description field.

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

func AgeRecipient(field, value string) error

AgeRecipient returns an error if value is not a valid age X25519 recipient.

func Blank

func Blank(field, value string) error

Blank returns an error if the string contains any non-whitespace content.

func Email

func Email(field, value string) error

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

func HTTPSURL(field, value string) error

HTTPSURL returns an error if value is not a valid HTTPS URL without private/internal IPs.

func JSONPath

func JSONPath(field, value string) error

JSONPath returns an error unless value is a simple dot-separated path with optional numeric indexes.

func MaxLen

func MaxLen(field, value string, max int) error

MaxLen returns an error if value exceeds max Unicode characters (rune count, not byte length).

func NoLeadingDot

func NoLeadingDot(field, value string) error

NoLeadingDot returns an error if value begins with a dot after trimming whitespace.

func NotBlank

func NotBlank(field, value string) error

NotBlank returns an error if the string is empty or contains only whitespace.

func OneOf

func OneOf(field, value string, allowed []string) error

OneOf returns an error if value is not one of the allowed values.

func PlainEmail

func PlainEmail(field, value string) error

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

func RequiredSlice[T any](field string, values []T) error

RequiredSlice returns an error if the slice is empty.

func TopicName

func TopicName(field, value string) error

TopicName returns an error if value does not match ^[a-z][a-z0-9_]{0,31}$.

func UniqueStrings

func UniqueStrings(field string, values []string) error

UniqueStrings returns an error if the slice contains duplicate string values.

func Validate

func Validate(checks ...error) []error

Validate collects the non-nil errors from the provided checks. Returns nil if all checks pass.

Types

This section is empty.

Jump to

Keyboard shortcuts

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