Documentation
¶
Index ¶
- func GetAttributeName(field string) string
- func SetAttributeName(field, name string)
- func SetAttributeNames(names map[string]string)
- func ValidateSometimes(data map[string]any, rules map[string][]string, conditions ...) map[string][]error
- func ValidateWithHooks(data map[string]any, rules map[string][]string, db *sql.DB, ...) map[string][]error
- func ValidateWithRules(data map[string]any, fieldRules map[string][]Rule) map[string][]error
- type AcceptedRule
- type ActiveURLRule
- type AfterDateRule
- type AfterValidationFunc
- type BeforeDateRule
- type BeforeValidationFunc
- type BooleanRule
- type ConfirmedRule
- type CurrentPasswordRule
- type CustomExistsRule
- type CustomRule
- type CustomUniqueRule
- type DeclinedRule
- type DifferentRule
- type DistinctRule
- type DoesntEndWithRule
- type DoesntStartWithRule
- type EmailRule
- type EnumRule
- type ExcludeRule
- type InRule
- type IntegerRule
- type MaxRule
- type MinRule
- type MissingRule
- type PresentRule
- type ProhibitedRule
- type RegexRule
- type RequiredRule
- type Rule
- type SometimesCondition
- type URLRule
- type UUIDRule
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAttributeName ¶
GetAttributeName returns the human-readable name for a field.
func SetAttributeName ¶
func SetAttributeName(field, name string)
SetAttributeName registers a human-readable name for a field.
func SetAttributeNames ¶
SetAttributeNames registers multiple field names at once.
func ValidateSometimes ¶
func ValidateSometimes(data map[string]any, rules map[string][]string, conditions ...struct { Field string When SometimesCondition RuleStr string }) map[string][]error
ValidateSometimes validates with conditional (sometimes) rules. Usage: ValidateSometimes(data, rules, Sometimes("role", "equals", "admin", "bio", "required"))
func ValidateWithHooks ¶
func ValidateWithHooks(data map[string]any, rules map[string][]string, db *sql.DB, before BeforeValidationFunc, after AfterValidationFunc) map[string][]error
ValidateWithHooks executes validation with optional lifecycle hooks.
Types ¶
type AcceptedRule ¶
type AcceptedRule struct{}
AcceptedRule validates that a field is "yes", "on", 1, or true.
type ActiveURLRule ¶
type ActiveURLRule struct{}
ActiveURLRule validates that a field has a valid A or AAAA record.
type AfterDateRule ¶
type AfterDateRule struct{}
AfterDateRule validates that a date is after another field.
type AfterValidationFunc ¶
AfterValidationFunc is a callback that runs after validation passes.
type BeforeDateRule ¶
type BeforeDateRule struct{}
BeforeDateRule validates that a date is before another field.
type BeforeValidationFunc ¶
BeforeValidationFunc is a callback that runs before validation.
type BooleanRule ¶
type BooleanRule struct{}
BooleanRule validates boolean values.
func (*BooleanRule) RuleName ¶
func (r *BooleanRule) RuleName() string
func (*BooleanRule) Validate ¶
func (r *BooleanRule) Validate(value any) error
type ConfirmedRule ¶
type ConfirmedRule struct{}
ConfirmedRule validates that two fields match.
type CurrentPasswordRule ¶
type CurrentPasswordRule struct{}
CurrentPasswordRule validates that the field matches the authenticated user's password.
type CustomExistsRule ¶
type CustomExistsRule struct {
// contains filtered or unexported fields
}
CustomExistsRule validates that a field exists in the database.
func NewCustomExistsRule ¶
func NewCustomExistsRule(table, column string) *CustomExistsRule
NewCustomExistsRule creates a new exists rule.
type CustomRule ¶
type CustomRule interface {
Passes(field string, value any, parameters []string) bool
Message(field string, parameters []string) string
}
CustomRule defines a custom validation rule interface (Laravel InvokableRule equivalent).
type CustomUniqueRule ¶
type CustomUniqueRule struct {
// contains filtered or unexported fields
}
CustomUniqueRule validates that a field is unique in the database.
func NewCustomUniqueRule ¶
func NewCustomUniqueRule(table, column string) *CustomUniqueRule
NewCustomUniqueRule creates a new unique rule.
type DeclinedRule ¶
type DeclinedRule struct{}
DeclinedRule validates that a field is "no", "off", 0, or false.
type DifferentRule ¶
type DifferentRule struct{}
DifferentRule validates that two fields have different values.
type DistinctRule ¶
type DistinctRule struct{}
DistinctRule validates that all array values are unique.
type DoesntEndWithRule ¶
type DoesntEndWithRule struct{}
DoesntEndWithRule validates that a field does not end with a specific value.
type DoesntStartWithRule ¶
type DoesntStartWithRule struct{}
DoesntStartWithRule validates that a field does not start with a specific value.
type EnumRule ¶
type EnumRule struct {
// contains filtered or unexported fields
}
EnumRule validates that a field is a valid enum value.
func NewEnumRule ¶
NewEnumRule creates a new enum rule.
type ExcludeRule ¶
type ExcludeRule struct{}
ExcludeRule always passes (used to exclude fields from validation).
type InRule ¶
type InRule struct{ Allowed []string }
InRule validates that the value is in a list of allowed values.
type IntegerRule ¶
type IntegerRule struct{}
IntegerRule validates integer values.
func (*IntegerRule) RuleName ¶
func (r *IntegerRule) RuleName() string
func (*IntegerRule) Validate ¶
func (r *IntegerRule) Validate(value any) error
type MaxRule ¶
type MaxRule struct{ Max float64 }
MaxRule validates maximum length (strings) or value (numbers).
type MinRule ¶
type MinRule struct{ Min float64 }
MinRule validates minimum length (strings) or value (numbers).
type MissingRule ¶
type MissingRule struct{}
MissingRule validates that a field is not present.
type PresentRule ¶
type PresentRule struct{}
PresentRule validates that a field is present.
type ProhibitedRule ¶
type ProhibitedRule struct{}
ProhibitedRule validates that a field is not present.
type RegexRule ¶
type RegexRule struct{ Pattern string }
RegexRule validates against a regex pattern.
type RequiredRule ¶
type RequiredRule struct{}
RequiredRule validates that a value is not empty.
func (*RequiredRule) RuleName ¶
func (r *RequiredRule) RuleName() string
func (*RequiredRule) Validate ¶
func (r *RequiredRule) Validate(value any) error
type SometimesCondition ¶
type SometimesCondition struct {
Field string
Operator string // "filled", "not_filled", "equals", "not_equals"
Value any
}
SometimesCondition defines when a rule should be applied.
func When ¶
func When(field, operator string, value any) SometimesCondition
When creates a SometimesCondition for use with Sometimes.