govalidator

A comprehensive Go package of string, numeric, and struct validators and sanitizers, modeled on validator.js.

Library
Go
vv0.0.0-20230301143203-a9d515a09cc2
6,205stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
59/100Fair
Development Activity44
Maintenance20
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
63/100Good
Architecture65
Code Quality72
Innovation45
Learning Curve70

govalidator is a dependency-free Go library that provides a large catalog of Is* validation functions (emails, URLs, UUIDs, credit cards, IP addresses, ISBNs, JSON, base64, semver, and dozens more), To* type-conversion helpers, and string sanitizers like BlackList, WhiteList, and NormalizeEmail. It is explicitly modeled on the popular JavaScript library validator.js, bringing the same breadth of individual validators to Go.

Beyond standalone functions, govalidator ships a reflection-based ValidateStruct/ValidateMap engine driven by valid:"..." struct tags, so entire structs (including nested structs, slices, and pointers) can be validated declaratively. Custom validators, parameterized validators, and type-specific validators can all be registered into shared maps, and both struct and map validation have async variants that report results over channels.

What You Get

  • Dozens of ready-made string validators — IsEmail, IsURL, IsUUID (v3/v4/v5), IsCreditCard, IsIP/IsIPv4/IsIPv6, IsISBN10/13, IsJSON, IsBase64, IsSemver, IsULID, and many more
  • A reflection-based ValidateStruct and ValidateMap engine driven by valid:"..." struct tags, with automatic recursion into nested structs, slices, and pointers
  • A pluggable validator registry (TagMap, ParamTagMap, CustomTypeTagMap, InterfaceParamTagMap) for registering custom or parameterized validation rules
  • String sanitizers — BlackList, WhiteList, NormalizeEmail, StripLow, and case/whitespace helpers
  • Type conversion helpers — ToInt, ToFloat, ToString, ToJSON, ToBoolean — with explicit error returns
  • Async validation via ValidateStructAsync and ValidateMapAsync, which report bool/error results over channels
  • Collection helpers over []interface{} — Filter, Each, Count, Find, ConditionIterator — for validating or transforming slices
  • A typed error model (Error/Errors) that tracks the failing field name, path, and validator for nested validation failures

Common Use Cases

  • Validating incoming API request payloads (emails, URLs, UUIDs, IPs) before they reach business logic
  • Declaratively validating config or form structs using valid:"..." tags instead of hand-written if-checks
  • Sanitizing untrusted user input (stripping disallowed characters, normalizing emails) before storage
  • Building custom domain-specific validators and registering them alongside the built-in ones for reuse across a codebase

Under The Hood

Architecture govalidator is a flat, single-package library (no internal subpackages) organized by concern across files: validator.go (the largest file, ~1,800 lines, holding both the individual Is* validators and the ValidateStruct/ValidateMap/ValidateArray reflection-based engine), types.go (validator function-type definitions and the concurrency-safe custom-validator registries backed by sync.RWMutex), patterns.go (regex constants), utils.go (sanitizers), numerics.go (numeric comparisons), arrays.go (slice iteration helpers), converter.go (type conversion), and error.go (the Error/Errors types implementing Go’s error interface with path tracking). ValidateStruct walks struct fields via reflect, parses valid tags into an ordered tagOptionsMap, and dispatches to whichever validator maps match, recursing automatically into nested structs, pointers, and slices. Because validation dispatch is centralized through these shared tag-parsing and registry data structures, changes to the tag-option format would ripple across every call site that uses ValidateStruct or ValidateMap.

Tech Stack The module (github.com/asaskevich/govalidator/v12, targeting Go 1.13) has zero third-party runtime dependencies — everything is built on the standard library (reflect, regexp, sync, net/mail, net/url, strings, sort). It is a leaf utility package meant to be imported directly rather than a service or CLI; there is no database, web framework, or build tooling beyond the Go toolchain itself. The repository still carries legacy CI configuration for Travis CI, CircleCI, and Wercker, but there is no active GitHub Actions workflow.

Code Quality Test coverage is extensive: validator_test.go alone runs to nearly 4,000 lines, with companion _test.go, _benchmark_test.go, and _example_test.go files for every domain file (arrays, converter, numerics, utils, validator), using only the standard testing package (no assertion library like testify). Error handling is explicit and typed — validation failures return an Errors slice of Error values carrying the field name, path, and failing validator rather than being swallowed — and naming is consistent throughout (Is* predicates, To* converters, Validate* engine functions). There is no linter configuration checked into the repo and no active CI workflow currently enforcing tests on new commits, which is a gap for an otherwise well-tested library.

What Makes It Unique govalidator’s differentiator is breadth rather than architectural novelty — it is explicitly a Go port of the popular JavaScript library validator.js, aiming to cover the same wide surface of individual format validators (emails, credit cards, ISBNs, IPs, UUID variants, ULIDs, semver, magnet URIs, and more) in one package. Its more distinctive design choice is combining that catalog with a declarative, struct-tag-driven validation engine that supports custom validator registration and channel-based async validation, giving it both a scripting-style function-call API and a schema-like declarative API in the same package.

Used by 7 apps in this directory

Go
60%
Apache 2.0

Apache Answer

Community

15,658

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
84
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Go
86%
Apache 2.0

Authelia

Security · Authentication

28,742

OpenID Certified SSO and MFA portal for securing self-hosted web applications behind reverse proxies.

View details
91
Repo Health
81
Technical
77
Dependency
Built with
Go86%
TypeScript12%
Updated today
Go
73%
Other

Convoy

Developer Tools · Devops

2,862

Convoy is an open-source, cloud-native webhooks gateway that ingests events over HTTP or straight from Kafka, SQS, Google Pub/Sub, and RabbitMQ, then reliably delivers them to subscriber endpoints with signed payloads, automatic retries, circuit breaking, and JavaScript-based transformations.

View details
89
Repo Health
81
Technical
66
Dependency
Built with
Go73%
TypeScript13%
HTML12%
Updated yesterday
Go
74%
Other

Notifuse

Marketing

2,089

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
83
Repo Health
80
Technical
66
Dependency
Built with
Go74%
TypeScript23%
Updated yesterday
Go
90%
BSD 3

tau

Devops

5,133

Open-source, Git-native platform-as-a-service for building, deploying, and scaling fullstack apps on your own infrastructure with no DevOps required.

View details
83
Repo Health
82
Technical
65
Dependency
Built with
Go90%
Updated 2 weeks ago
Go
95%
Apache 2.0

TiDB

Databases · AI Development

40,477

AI-Native Distributed SQL Database for Agentic Workloads

View details
97
Repo Health
66
Technical
68
Dependency
Built with
Go95%
Updated today
Go
73%
AGPL 3.0

Vikunja

Project Management

5,206

Self-hosted task management with natural-language quick-add, multiple views, and a fully documented REST API — your tasks, your infrastructure, zero lock-in.

View details
86
Repo Health
81
Technical
74
Dependency
Built with
Go73%
TypeScript14%
Vue12%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search