Documentation
¶
Index ¶
- func RegisterRule(name string, handler RuleHandler)
- func ValidateValue(value interface{}, rule string) error
- type Messages
- type RuleHandler
- type RuleRegistry
- type Rules
- type ValidatedData
- func (v *ValidatedData) All() map[string]interface{}
- func (v *ValidatedData) Errors() ValidationErrors
- func (v *ValidatedData) Get(key string) interface{}
- func (v *ValidatedData) GetBool(key string) bool
- func (v *ValidatedData) GetInt(key string) int
- func (v *ValidatedData) GetString(key string) string
- func (v *ValidatedData) HasErrors() bool
- type ValidationErrors
- func (e ValidationErrors) All() map[string][]string
- func (e ValidationErrors) Count() int
- func (e ValidationErrors) Error() string
- func (e ValidationErrors) First(field string) string
- func (e ValidationErrors) HasError(field string) bool
- func (e ValidationErrors) IsEmpty() bool
- func (e *ValidationErrors) Merge(other ValidationErrors)
- type Validator
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 ¶
ValidateValue validates a single value
Types ¶
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 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 ¶
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