Help us shape the future of Go! Take the 2026 Go Developer Survey

validate

package
v1.6.11 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package validate provides validation for LValue types. Validators register via init() for plugin-based extensibility.

Index

Constants

This section is empty.

Variables

View Source
var Default = New()

Default is the global registry with built-in validators.

Functions

func GetRegex

func GetRegex(pattern string) *regexp.Regexp

GetRegex returns cached compiled regex. Returns nil for invalid patterns.

func Register

func Register(name string, fn Func)

Register adds a validator to the default context.

Types

type Error

type Error struct {
	Field      string
	Message    string
	Got        any
	Expected   any
	Constraint string
}

Error represents a validation failure.

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

type Func

type Func func(val any, arg any) *Error

Func validates a value against an annotation argument. Val is always an LValue from the lua package.

type Registry

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

Registry holds validators.

func New

func New() *Registry

New creates empty registry.

func (*Registry) CheckAnnotations

func (r *Registry) CheckAnnotations(val any, annotations map[string]any, path string, errors *[]*Error)

CheckAnnotations runs validators for annotations.

func (*Registry) Get

func (r *Registry) Get(name string) Func

Get returns a validator by name.

func (*Registry) RegisterValidator

func (r *Registry) RegisterValidator(name string, fn Func)

RegisterValidator adds a validator to this registry.

Jump to

Keyboard shortcuts

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