How go-playground/validator works
Core Components (Center
• It to these primary subcomponents:
• Field Level Validator
• Struct Level Validator
• Cache System
• Tag Parser
Validation Types Layer (Surrounding Core)
• Built-in Validators
• Network Validators
• String Validators
• Format Validators
• Comparison Validators
• Custom Validators
• Cross-Field Validators
• Struct Level Validators
Translation System (Side Component)
• Translation Manager
• Language Files Repository
• To supported languages (ar, en, es, fa, fr, etc.)
• Error Message Formatter
Integration Layer (Top Layer)
Integration points:
• Gin Framework Integration
• Custom Type Handling
• Interface Validation
• SQL Driver Support
• Input: Struct/Field → Validator Core
• Processing: Core → Specific Validators
• Output: Validation Results → Error Handling
Special Features (Side Panels)
• Dive Functionality (for slices/maps)
• Cache System
• Tag Parsing System
• Custom Error Formatting
Specific Implementation Details:
Clear separation between
• Tag Processing
• Validation Logic
• Error Handling
• Translation System
Files and their roles
• validator.go → Main Engine
• cache.go → Caching System
• translations/ → i18n Support
• baked_in.go → Built-in Validators
Important interfaces
• FieldLevel
• StructLevel
• Validator
• CustomTypeFunc