Documentation
¶
Overview ¶
Package validation provides validation rules and utilities for DynamORM model data integrity.
Index ¶
- func ValidateModel(model any) error
- func ValidateRequest(request any) error
- func ValidateWithTags(model any) error
- type AlphaNumRule
- type AlphaRule
- type ContentRule
- type DateRule
- type EmailRule
- type InRule
- type IntegerRule
- type LengthRule
- type MaxLengthRule
- type MaxRule
- type MinLengthRule
- type MinRule
- type NotInRule
- type NumericRule
- type PasswordRule
- type PatternRule
- type RequiredRule
- type Rule
- type URLRule
- type UsernameRule
- type ValidationConstraints
- type ValidationError
- type ValidationErrors
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateModel ¶
ValidateModel validates a DynamORM model before saving
func ValidateRequest ¶
ValidateRequest validates a request payload using struct tags
func ValidateWithTags ¶
ValidateWithTags validates a struct using struct tags
Types ¶
type AlphaNumRule ¶
type AlphaNumRule struct{}
AlphaNumRule validates that string contains only alphanumeric characters
func (AlphaNumRule) Message ¶
func (r AlphaNumRule) Message() string
Message returns the validation error message for AlphaNumRule
func (AlphaNumRule) Validate ¶
func (r AlphaNumRule) Validate(value any) error
Validate checks that the string contains only alphanumeric characters
type AlphaRule ¶
type AlphaRule struct{}
AlphaRule validates that string contains only alphabetic characters
type ContentRule ¶
type ContentRule struct {
Constraints ValidationConstraints
}
ContentRule validates status content according to Lesser's requirements
func (ContentRule) Message ¶
func (r ContentRule) Message() string
Message returns the validation error message for ContentRule
func (ContentRule) Validate ¶
func (r ContentRule) Validate(value any) error
Validate checks that the content meets Lesser's requirements
type DateRule ¶
type DateRule struct{}
DateRule validates that value is a valid date
type EmailRule ¶
type EmailRule struct{}
EmailRule validates email format
type InRule ¶
type InRule struct {
AllowedValues []string
}
InRule validates that value is in a list of allowed values
type IntegerRule ¶
type IntegerRule struct{}
IntegerRule validates that value is an integer
func (IntegerRule) Message ¶
func (r IntegerRule) Message() string
Message returns the validation error message for IntegerRule
func (IntegerRule) Validate ¶
func (r IntegerRule) Validate(value any) error
Validate checks that the value is an integer
type LengthRule ¶
type LengthRule struct {
Length int
}
LengthRule validates exact string length
func (LengthRule) Message ¶
func (r LengthRule) Message() string
Message returns the validation error message for LengthRule
func (LengthRule) Validate ¶
func (r LengthRule) Validate(value any) error
Validate checks that the string value has exactly the required length
type MaxLengthRule ¶
type MaxLengthRule struct {
MaxLength int
}
MaxLengthRule validates maximum string length
func (MaxLengthRule) Message ¶
func (r MaxLengthRule) Message() string
Message returns the validation error message for MaxLengthRule
func (MaxLengthRule) Validate ¶
func (r MaxLengthRule) Validate(value any) error
Validate checks that the string or slice value does not exceed the maximum length
type MaxRule ¶
type MaxRule struct {
Max float64
}
MaxRule validates maximum numeric value
type MinLengthRule ¶
type MinLengthRule struct {
MinLength int
}
MinLengthRule validates minimum string length
func (MinLengthRule) Message ¶
func (r MinLengthRule) Message() string
Message returns the validation error message for MinLengthRule
func (MinLengthRule) Validate ¶
func (r MinLengthRule) Validate(value any) error
Validate checks that the string value meets the minimum length requirement
type MinRule ¶
type MinRule struct {
Min float64
}
MinRule validates minimum numeric value
type NotInRule ¶
type NotInRule struct {
DisallowedValues []string
}
NotInRule validates that value is not in a list of disallowed values
type NumericRule ¶
type NumericRule struct{}
NumericRule validates that value is numeric
func (NumericRule) Message ¶
func (r NumericRule) Message() string
Message returns the validation error message for NumericRule
func (NumericRule) Validate ¶
func (r NumericRule) Validate(value any) error
Validate checks that the value is numeric
type PasswordRule ¶
type PasswordRule struct {
Constraints ValidationConstraints
}
PasswordRule validates passwords according to Lesser's security requirements
func (PasswordRule) Message ¶
func (r PasswordRule) Message() string
Message returns the validation error message for PasswordRule
func (PasswordRule) Validate ¶
func (r PasswordRule) Validate(value any) error
Validate checks that the password meets Lesser's security requirements
type PatternRule ¶
PatternRule validates using a regular expression
func (PatternRule) Message ¶
func (r PatternRule) Message() string
Message returns the validation error message for PatternRule
func (PatternRule) Validate ¶
func (r PatternRule) Validate(value any) error
Validate checks that the string value matches the regular expression pattern
type RequiredRule ¶
type RequiredRule struct{}
RequiredRule validates that a value is not empty/zero
func (RequiredRule) Message ¶
func (r RequiredRule) Message() string
Message returns the validation error message for RequiredRule
func (RequiredRule) Validate ¶
func (r RequiredRule) Validate(value any) error
Validate checks that the value is not empty or zero
type URLRule ¶
type URLRule struct{}
URLRule validates URL format
type UsernameRule ¶
type UsernameRule struct {
Constraints ValidationConstraints
}
UsernameRule validates usernames according to Lesser's requirements
func (UsernameRule) Message ¶
func (r UsernameRule) Message() string
Message returns the validation error message for UsernameRule
func (UsernameRule) Validate ¶
func (r UsernameRule) Validate(value any) error
Validate checks that the username meets Lesser's requirements
type ValidationConstraints ¶
type ValidationConstraints struct {
Username struct {
MinLength int
MaxLength int
Pattern *regexp.Regexp
}
Email struct {
MaxLength int
}
Password struct {
MinLength int
RequireUpper bool
RequireLower bool
RequireDigit bool
RequireSpecial bool
}
Content struct {
MaxLength int
}
}
ValidationConstraints provides predefined validation constraints for common model fields
func DefaultConstraints ¶
func DefaultConstraints() ValidationConstraints
DefaultConstraints provides default validation constraints for the Lesser project
type ValidationError ¶
type ValidationError struct {
Field string `json:"field"`
Message string `json:"message"`
Value any `json:"value,omitempty"`
}
ValidationError represents a validation error
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type ValidationErrors ¶
type ValidationErrors struct {
Errors []ValidationError `json:"errors"`
}
ValidationErrors represents multiple validation errors
func (*ValidationErrors) Add ¶
func (e *ValidationErrors) Add(field, message string, value any)
Add adds a validation error
func (ValidationErrors) Error ¶
func (e ValidationErrors) Error() string
func (ValidationErrors) HasErrors ¶
func (e ValidationErrors) HasErrors() bool
HasErrors returns true if there are validation errors
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates struct fields
func CreateModelValidator ¶
CreateModelValidator creates a validator with common model rules
func NewValidator ¶
NewValidator creates a new validator