Documentation
¶
Index ¶
- func AllTrue[T any](items []T, predicate func(T) bool) bool
- func MaxLength(value string, max int, field string, result *ValidationResult)
- func MinLength(value string, min int, field string, result *ValidationResult)
- func PastDate(value time.Time, field string, result *ValidationResult)
- func Pattern(value, pattern, field string, result *ValidationResult)
- func Required(value, field string, result *ValidationResult)
- func ValidDateRange(start, end time.Time, startField, endField string, result *ValidationResult)
- func ValidateAll[T any](items []T, validator func(T, int, *ValidationResult), result *ValidationResult)
- func ValidateID(id, field string, result *ValidationResult)
- type ValidationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MaxLength ¶
func MaxLength(value string, max int, field string, result *ValidationResult)
MaxLength validates that a string has a maximum length
func MinLength ¶
func MinLength(value string, min int, field string, result *ValidationResult)
MinLength validates that a string has a minimum length
func PastDate ¶
func PastDate(value time.Time, field string, result *ValidationResult)
PastDate validates that a date is in the past
func Pattern ¶
func Pattern(value, pattern, field string, result *ValidationResult)
Pattern validates that a string matches a regular expression
func Required ¶
func Required(value, field string, result *ValidationResult)
Required validates that a string is not empty
func ValidDateRange ¶
func ValidDateRange(start, end time.Time, startField, endField string, result *ValidationResult)
ValidDateRange validates that a start date is before an end date
func ValidateAll ¶
func ValidateAll[T any](items []T, validator func(T, int, *ValidationResult), result *ValidationResult)
ValidateAll validates all items in a slice
func ValidateID ¶
func ValidateID(id, field string, result *ValidationResult)
ValidateID validates that an ID is not empty
Types ¶
type ValidationResult ¶
type ValidationResult struct {
// contains filtered or unexported fields
}
ValidationResult holds the result of a validation operation
func NewValidationResult ¶
func NewValidationResult() *ValidationResult
NewValidationResult creates a new ValidationResult
func (*ValidationResult) AddError ¶
func (v *ValidationResult) AddError(msg, field string)
AddError adds an error to the validation result
func (*ValidationResult) Error ¶
func (v *ValidationResult) Error() error
Error returns the validation errors as an error
func (*ValidationResult) IsValid ¶
func (v *ValidationResult) IsValid() bool
IsValid returns true if there are no validation errors