Stop Hand-Rolling Validation in Go — Meet Checker
If you've written more than one HTTP handler in Go, you've written this code: if strings . TrimSpace ( req . Name ) == "" { return errors . New ( "name is required" ) } if ! strings . Contains ( req . Email , "@" ) { return errors . New ( "invalid email" ) } if req . ConfirmPassword != req . Password { return errors . New ( "passwords do not match" ) } It starts small. Then a new field shows up,…
Go developers who have written multiple HTTP handlers often encounter repetitive validation code, such as trimming whitespace, checking email format, and comparing passwords. This code can quickly become a tangled mess of if statements, making it difficult to maintain and extend. Checker is a Go library designed to simplify this process.
By using declarative struct tags and a single function call, Checker eliminates the need for a large pile of if statements. It supports normalization, cross-field rules, conditional rules, and more, all declared alongside the fields they apply to. Checker has zero dependencies beyond the Go standard library, making it lightweight and easy to incorporate into projects.
Additionally, it provides built-in localization support, structured error handling, and even the ability to generate a JSON Schema from your struct tags.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.