validate

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package validate provides Runa validate primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Invalid

func Invalid(items ...FieldError) error

Invalid returns a validation error.

Types

type Field

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

Field defines validation rules for one field.

func (*Field) Call

func (field *Field) Call(handler any) *Field

Call adds a field-level callback.

func (*Field) Email

func (field *Field) Email(message string) *Field

Email requires a valid email value.

func (*Field) Max

func (field *Field) Max(max float64, message string) *Field

Max requires a numeric value to be less than or equal to max.

func (*Field) MaxLen

func (field *Field) MaxLen(max int, message string) *Field

MaxLen requires a string length to be less than or equal to max.

func (*Field) Min

func (field *Field) Min(min float64, message string) *Field

Min requires a numeric value to be greater than or equal to min.

func (*Field) MinLen

func (field *Field) MinLen(min int, message string) *Field

MinLen requires a string length to be greater than or equal to min.

func (*Field) Regex

func (field *Field) Regex(pattern string, message string) *Field

Regex requires a string value to match pattern.

func (*Field) Required

func (field *Field) Required(message string) *Field

Required requires a non-zero value.

func (*Field) Value

func (field *Field) Value(value any) *Field

Value sets an explicit value for this field.

type FieldError

type FieldError struct {
	Source  string
	Field   string
	Name    string
	Code    string
	Message string
	Params  core.Map
}

FieldError describes a single validation field error.

type FieldSchema

type FieldSchema struct {
	Source      string
	Name        string
	Field       string
	Label       string
	Description string
	Default     string
	Type        string
	Format      string
}

FieldSchema stores input field metadata collected from struct tags.

type ValidationError

type ValidationError struct {
	Errors []FieldError
	Cause  error
}

ValidationError describes validation errors.

func AsError

func AsError(err error) *ValidationError

AsError returns a ValidationError when err contains one.

func (*ValidationError) Error

func (err *ValidationError) Error() string

Error returns the first field error message or a default message.

func (*ValidationError) ErrorCode

func (err *ValidationError) ErrorCode() string

ErrorCode returns the standard error code.

func (*ValidationError) ErrorFields

func (err *ValidationError) ErrorFields() []FieldError

ErrorFields returns validation field errors for renderers.

func (*ValidationError) ErrorMessage

func (err *ValidationError) ErrorMessage() string

ErrorMessage returns the public error message.

func (*ValidationError) ErrorParams

func (err *ValidationError) ErrorParams() core.Map

ErrorParams returns translation/rendering parameters for the first field error.

func (*ValidationError) ErrorStatus

func (err *ValidationError) ErrorStatus() int

ErrorStatus returns the HTTP status.

func (*ValidationError) Unwrap

func (err *ValidationError) Unwrap() error

Unwrap returns the cause error.

type Validator

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

Validator validates a bound input or an explicit value set.

func New

func New(target any, ctx any) *Validator

New creates a Validator.

func (*Validator) AddError

func (validator *Validator) AddError(item FieldError)

AddError adds a field error.

func (*Validator) Check

func (validator *Validator) Check(handler any) *Validator

Check adds an input-level validation callback.

func (*Validator) Field

func (validator *Validator) Field(name string) *Field

Field selects a field by dotted Go struct field path.

func (*Validator) Run

func (validator *Validator) Run() error

Run executes all rules and callbacks.

Jump to

Keyboard shortcuts

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