validation

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package validation defines the validation contract.

There is no reflection and there are no struct tags: every request type implements Validate and returns the errors per field. It is more verbose than `binding:"required"`, and deliberately so -- the message is written by whoever knows the domain, and the CLI generates the method skeleton along with the struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Email

func Email(e Errors, field, value string)

Email checks the shape only. Deliverability is proven by sending mail, never by a regular expression.

Whitespace is rejected rather than trimmed: an address with a space in it is almost always a paste accident, and silently trimming input hides the mistake from the person who made it.

func MaxLen

func MaxLen(e Errors, field, value string, n int)

MaxLen counts runes, not bytes.

func MinLen

func MinLen(e Errors, field, value string, n int)

MinLen counts runes, not bytes: a limit measured in bytes rejects valid input in any language that needs more than one byte per character.

func Required

func Required(e Errors, field, value string)

Required rejects an empty or blank value.

Types

type Errors

type Errors map[string][]string

Errors maps a field to its messages. It serializes straight into the HTMX partial that re-renders the form with inline errors.

func (Errors) Add

func (e Errors) Add(field, msg string)

Add appends a message to a field. It is a no-op on a nil map, so a caller that forgot to initialize the map does not panic in the middle of a request.

func (Errors) Any

func (e Errors) Any() bool

Any reports whether validation failed.

func (Errors) Error

func (e Errors) Error() string

Error renders the errors with fields in a stable order, so that logs and golden files do not change between runs.

type Validatable

type Validatable interface {
	Validate() Errors
}

Validatable is implemented by every request type.

Jump to

Keyboard shortcuts

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