Documentation
¶
Overview ¶
Package validation provides comprehensive form validation utilities for validating form schemas, submissions, and generating client-side rules.
Index ¶
- Constants
- Variables
- type ComprehensiveValidator
- type Error
- type FieldValidation
- type FieldValidator
- type FieldValidatorInterface
- type FormValidator
- type FormValidatorInterface
- type Result
- type Rule
- type SchemaGenerator
- type SchemaParser
- func (p *SchemaParser) ConvertToClientRules(validation *FieldValidation) map[string]any
- func (p *SchemaParser) ExtractComponentKey(component map[string]any) (string, bool)
- func (p *SchemaParser) ExtractComponents(schema map[string]any) ([]any, bool)
- func (p *SchemaParser) ExtractValidationRules(component map[string]any) FieldValidation
Constants ¶
const ( // ValidateRequired is the validation rule for required fields ValidateRequired = "required" // ValidatePassword is the validation rule for password fields ValidatePassword = "password" )
Variables ¶
var Module = fx.Module("validation", fx.Provide( infra_validation.New, NewSchemaGenerator, fx.Annotate( NewFormValidator, ), ), )
Module provides validation dependencies
Functions ¶
This section is empty.
Types ¶
type ComprehensiveValidator ¶
type ComprehensiveValidator struct {
// contains filtered or unexported fields
}
ComprehensiveValidator provides comprehensive form validation
func NewComprehensiveValidator ¶
func NewComprehensiveValidator() *ComprehensiveValidator
NewComprehensiveValidator creates a new comprehensive form validator
func (*ComprehensiveValidator) GenerateClientValidation ¶
func (v *ComprehensiveValidator) GenerateClientValidation(schema model.JSON) (map[string]any, error)
GenerateClientValidation generates client-side validation rules from schema
func (*ComprehensiveValidator) ValidateForm ¶
func (v *ComprehensiveValidator) ValidateForm(schema, submission model.JSON) Result
ValidateForm validates a form submission against its schema
type Error ¶
type Error struct {
Field string `json:"field"`
Message string `json:"message"`
Rule string `json:"rule,omitempty"`
}
Error represents a validation error for a specific field
type FieldValidation ¶
type FieldValidation struct {
Required bool `json:"required,omitempty"`
Type string `json:"type,omitempty"`
MinLength int `json:"min_length,omitempty"`
MaxLength int `json:"max_length,omitempty"`
Min float64 `json:"min,omitempty"`
Max float64 `json:"max,omitempty"`
Pattern string `json:"pattern,omitempty"`
Options []string `json:"options,omitempty"`
CustomRules []Rule `json:"custom_rules,omitempty"`
Conditional map[string]any `json:"conditional,omitempty"`
}
FieldValidation represents validation rules for a specific field
type FieldValidator ¶
type FieldValidator struct {
// contains filtered or unexported fields
}
FieldValidator handles field-specific validation logic
func NewFieldValidator ¶
func NewFieldValidator() *FieldValidator
NewFieldValidator creates a new field validator
func (*FieldValidator) ValidateField ¶
func (v *FieldValidator) ValidateField(fieldName string, value any, rules *FieldValidation) []Error
ValidateField validates a single field against its rules
func (*FieldValidator) ValidateFieldType ¶
func (v *FieldValidator) ValidateFieldType(fieldName string, value any, fieldType string) *Error
ValidateFieldType validates the type of a field
type FieldValidatorInterface ¶
type FieldValidatorInterface interface {
ValidateField(fieldName string, value any, rules FieldValidation) []Error
ValidateFieldType(fieldName string, value any, fieldType string) *Error
}
FieldValidatorInterface defines the interface for field-specific validation
type FormValidator ¶
type FormValidator struct {
// contains filtered or unexported fields
}
FormValidator provides form-specific validation utilities
func NewFormValidator ¶
func NewFormValidator(logger logging.Logger) *FormValidator
NewFormValidator creates a new form validator
func (*FormValidator) ValidateFormData ¶
func (fv *FormValidator) ValidateFormData(data, schema map[string]any) error
ValidateFormData validates form data against a schema
func (*FormValidator) ValidateFormID ¶
func (fv *FormValidator) ValidateFormID(c echo.Context) (string, error)
ValidateFormID validates that a form ID parameter exists
func (*FormValidator) ValidateFormSchema ¶
func (fv *FormValidator) ValidateFormSchema(schema map[string]any) error
ValidateFormSchema validates a form schema structure
type FormValidatorInterface ¶
type FormValidatorInterface interface {
ValidateForm(schema map[string]any, submission map[string]any) Result
GenerateClientValidation(schema map[string]any) (map[string]any, error)
}
FormValidatorInterface defines the interface for form validation
type Rule ¶
type Rule struct {
Type string `json:"type"`
Value any `json:"value,omitempty"`
Message string `json:"message,omitempty"`
Condition string `json:"condition,omitempty"` // For conditional validation
}
Rule represents a validation rule for a form field
type SchemaGenerator ¶
type SchemaGenerator struct{}
SchemaGenerator provides functionality to generate validation schemas from struct tags
func NewSchemaGenerator ¶
func NewSchemaGenerator() *SchemaGenerator
NewSchemaGenerator creates a new schema generator
func (*SchemaGenerator) GenerateLoginSchema ¶
func (sg *SchemaGenerator) GenerateLoginSchema() map[string]any
GenerateLoginSchema generates the validation schema for login forms
func (*SchemaGenerator) GenerateSignupSchema ¶
func (sg *SchemaGenerator) GenerateSignupSchema() map[string]any
GenerateSignupSchema generates the validation schema for signup forms
func (*SchemaGenerator) GenerateValidationSchema ¶
func (sg *SchemaGenerator) GenerateValidationSchema(s any) map[string]any
GenerateValidationSchema generates a validation schema from a struct
type SchemaParser ¶
type SchemaParser struct{}
SchemaParser handles parsing and extracting validation rules from form schemas
func NewSchemaParser ¶
func NewSchemaParser() *SchemaParser
NewSchemaParser creates a new schema parser
func (*SchemaParser) ConvertToClientRules ¶
func (p *SchemaParser) ConvertToClientRules(validation *FieldValidation) map[string]any
ConvertToClientRules converts server-side validation rules to client-side format
func (*SchemaParser) ExtractComponentKey ¶
func (p *SchemaParser) ExtractComponentKey(component map[string]any) (string, bool)
ExtractComponentKey extracts the key from a component
func (*SchemaParser) ExtractComponents ¶
func (p *SchemaParser) ExtractComponents(schema map[string]any) ([]any, bool)
ExtractComponents extracts components from a form schema
func (*SchemaParser) ExtractValidationRules ¶
func (p *SchemaParser) ExtractValidationRules(component map[string]any) FieldValidation
ExtractValidationRules extracts validation rules from a component