validate

package
v1.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatErrors

func FormatErrors(errs []Error) string

FormatErrors joins all errors into a single multi-line string.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker accumulates validation errors as you check fields.

func (*Checker) Check

func (c *Checker) Check(path, value string, cond bool, msg string)

Check adds a custom error if cond is false.

func (*Checker) Errors

func (c *Checker) Errors() []Error

Errors returns all accumulated errors. Nil if everything is valid.

func (*Checker) FloatMax

func (c *Checker) FloatMax(path string, value float64, max *float64)

FloatMax checks that value is <= max. Skips if max is nil.

func (*Checker) FloatMin

func (c *Checker) FloatMin(path string, value float64, min *float64)

FloatMin checks that value is >= min. Skips if min is nil.

func (*Checker) HasErrors

func (c *Checker) HasErrors() bool

HasErrors returns true if any errors were recorded.

func (*Checker) IntMin

func (c *Checker) IntMin(path string, value, min int)

IntMin checks that value is >= min. Skips if 0.

func (*Checker) IntRange

func (c *Checker) IntRange(path string, value, min, max int)

IntRange checks that value is within [min, max]. Skips if value is 0 (zero value means "use default").

func (*Checker) LessOrEqual

func (c *Checker) LessOrEqual(pathA string, a int, pathB string, b int)

LessOrEqual checks a <= b. Skips if either is 0.

func (*Checker) MaxLength

func (c *Checker) MaxLength(path string, value string, max *int)

MaxLength checks that a string's length does not exceed max. Skips if max is nil.

func (*Checker) OneOf

func (c *Checker) OneOf(path, value string, allowed []string)

OneOf checks that value is one of the allowed strings. Skips if value is empty (zero value means "use default").

func (*Checker) Required

func (c *Checker) Required(path, value string)

Required checks that value is non-empty.

type Error

type Error struct {
	Path    string // dotted field path, e.g. "collections.docs.layout"
	Value   string // the invalid value (stringified for display)
	Message string // human-readable explanation with valid options
}

Error describes a single validation failure.

func (Error) Error

func (e Error) Error() string

Jump to

Keyboard shortcuts

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