validate

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 5 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. An enumeration's list of allowed values is printed once: a later error with the same list (every bad entry of plugins.enabled) refers back to it.

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"). The error lists the allowed values sorted and without duplicates, so it reads the same on every run, and suggests the closest one when value looks like a typo.

func (*Checker) Required

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

Required checks that value is non-empty.

type Error

type Error struct {
	Path    string   `json:"path"`              // dotted field path, e.g. "collections.docs.layout"
	Value   string   `json:"value,omitempty"`   // the invalid value (stringified for display)
	Message string   `json:"message"`           // human-readable explanation with valid options
	Allowed []string `json:"allowed,omitempty"` // valid values when the check was an enumeration
	// Suggestion is the allowed value closest to Value, when it looks like a
	// typo of one (an edit distance of 2 or less).
	Suggestion string `json:"suggestion,omitempty"`
}

Error describes a single validation failure. The json tags define the machine-readable shape emitted by `--format json` error envelopes (consumed by Sarde Studio); keep them stable.

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