validation

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRule

func RegisterRule(name string, handler RuleHandler)

RegisterRule registers a custom validation rule globally

func ValidateValue

func ValidateValue(value interface{}, rule string) error

ValidateValue validates a single value

Types

type Messages

type Messages map[string]string

Messages defines custom error messages

type RuleHandler

type RuleHandler func(field string, value interface{}, params []string, data map[string]interface{}) error

RuleHandler defines a validation rule function

type RuleRegistry

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

RuleRegistry manages validation rules

func (*RuleRegistry) Get

func (r *RuleRegistry) Get(name string) (RuleHandler, bool)

Get retrieves a validation rule handler

func (*RuleRegistry) Register

func (r *RuleRegistry) Register(name string, handler RuleHandler)

Register registers a validation rule

type Rules

type Rules map[string]string

Rules defines validation rules for fields

type ValidatedData

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

ValidatedData contains validated and cleaned data

func Validate

func Validate(data interface{}, rules Rules) (*ValidatedData, error)

Validate validates data against rules

func ValidateRequest

func ValidateRequest(r *http.Request, rules Rules) (*ValidatedData, error)

ValidateRequest validates an HTTP request

func (*ValidatedData) All

func (v *ValidatedData) All() map[string]interface{}

All returns all validated data

func (*ValidatedData) Errors

func (v *ValidatedData) Errors() ValidationErrors

Errors returns validation errors

func (*ValidatedData) Get

func (v *ValidatedData) Get(key string) interface{}

Get retrieves a validated value by key

func (*ValidatedData) GetBool

func (v *ValidatedData) GetBool(key string) bool

GetBool retrieves a boolean value

func (*ValidatedData) GetInt

func (v *ValidatedData) GetInt(key string) int

GetInt retrieves an integer value

func (*ValidatedData) GetString

func (v *ValidatedData) GetString(key string) string

GetString retrieves a string value

func (*ValidatedData) HasErrors

func (v *ValidatedData) HasErrors() bool

HasErrors returns true if validation failed

type ValidationErrors

type ValidationErrors struct {
	Errors map[string][]string
}

ValidationErrors represents validation errors

func (ValidationErrors) All

func (e ValidationErrors) All() map[string][]string

All returns all error messages

func (ValidationErrors) Count

func (e ValidationErrors) Count() int

Count returns the total number of errors

func (ValidationErrors) Error

func (e ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) First

func (e ValidationErrors) First(field string) string

First returns the first error message for a field

func (ValidationErrors) HasError

func (e ValidationErrors) HasError(field string) bool

HasError checks if a specific field has errors

func (ValidationErrors) IsEmpty

func (e ValidationErrors) IsEmpty() bool

IsEmpty returns true if there are no errors

func (*ValidationErrors) Merge

func (e *ValidationErrors) Merge(other ValidationErrors)

Merge merges another ValidationErrors into this one

type Validator

type Validator interface {
	Validate(data interface{}, rules Rules) (*ValidatedData, error)
	ValidateRequest(r *http.Request, rules Rules) (*ValidatedData, error)
	ValidateValue(value interface{}, rule string) error
	SetMessages(messages Messages)
	SetLocale(locale string)
}

Validator provides validation functionality

func Get

func Get() Validator

Get returns the global validator instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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