About
Type-safe form and request validation for Go applications with reusable schemas, composable rules, conditional validation, HTTP binding, and structured error responses.
NLG Form
form is a type-safe form and request validation package for Go applications.
It helps you define reusable validation schemas using typed fields, composable rules, optional values, conditional logic, and structured error responses. The package is designed for validating JSON requests, API payloads, forms, and application input while keeping validation logic explicit, reusable, and easy to test.
It provides strongly typed field definitions, reusable validation pipelines, optional and conditional validation helpers, HTTP form integration, and structured validation error handling while remaining lightweight and fully compatible with Go’s standard library.
Features
- Type-Safe Form Schemas: Define reusable validation schemas using Go generics and typed field accessors
- Composable Validation Rules: Build reusable validation pipelines from small chainable rules
- Reusable Schema Composition: Combine smaller schemas into larger validation workflows
- String, Number, Boolean, Slice, and Time Rules: Validate common Go types through dedicated rule helpers
- Required and Optional Fields: Support required values, nullable inputs, pointer fields, and optional validation flows
- Conditional Validation: Apply validation rules dynamically based on runtime conditions
- Cross-Field Validation: Compare values between fields such as password confirmation, ranges, or dependent inputs
- Format Validators: Validate emails, URLs, UUIDs, IP addresses, JSON payloads, timezones, and custom formats
- Custom Validation Rules: Create application-specific validators with reusable logic
- HTTP Request Binding: Decode and validate JSON request bodies directly from
net/httphandlers - Structured Validation Errors: Return validation errors as field maps, flat lists, or custom response formats
- Custom Error Codes: Override default validation codes for application-specific API responses
- Unique Error Codes: Optionally remove duplicated validation codes per field
- Nested Validation Support: Compose deeply structured validation trees from reusable field definitions
- Concurrency-Safe Design: Safe for concurrent validation in APIs, services, and background workers
- Standard Library Friendly: Works naturally with Go structs,
encoding/json,net/http, and standard application layers - Minimal Dependencies: Lightweight implementation built primarily on Go’s standard library
- Practical Validation Workflows: Suitable for APIs, registration flows, sign-in forms, profile updates, billing systems, CLI tools, and internal services
Requirements
This package requires Go 1.22 or newer.
It is designed for modern Go projects and may use language and standard library features introduced in recent Go versions.
- Go:
1.22or newer - Dependencies: Standard library only
- Features used: Generics, concurrency primitives
The package is optimized for clean validation workflows and reusable schema composition, making it suitable for APIs, backend services, form validation, request processing, and structured application input handling.