Skip to content
Package60 repository health

govalidator

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

Library Govv0.0.0-20230301143203-a9d515a09cc26,202 stars MIT License
go get github.com/asaskevich/govalidator
View source

Repository health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
Good
  • Development activity48
  • Maintenance20
  • Community72
  • Maturity60
  • Momentum40

Technical analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
Good
  • 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

Every app whose dependencies include github.com/asaskevich/govalidator, nine to a page.

Go 61%Apache 2.0

Apache Answer

15,708

Community

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

App
Built with
  • Go 61%
  • TypeScript 36%
Updated 2 weeks agoView details
Go 82%Apache 2.0

Authelia

29,580

Authentication · Security

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

App
Built with
  • Go 82%
  • TypeScript 15%
Updated 2 weeks agoView details
Go 71%Other

Convoy

2,888

Developer Tools · Devops

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.

App
Built with
  • Go 71%
  • TypeScript 15%
  • HTML 12%
Updated 2 weeks agoView details
Go 76%Other

Notifuse

2,273

Marketing

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

App
Built with
  • Go 76%
  • TypeScript 21%
Updated 2 weeks agoView details
Go 90%BSD 3

tau

5,165

Devops

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

App
Built with
  • Go 90%
Updated 2 weeks agoView details
Go 95%Apache 2.0

TiDB

40,715

AI Development · Databases

AI-Native Distributed SQL Database for Agentic Workloads

App
Built with
  • Go 95%
Updated 2 weeks agoView details
Go 69%AGPL 3.0

Vikunja

5,979

Project Management

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

App
Built with
  • Go 69%
  • TypeScript 20%
Updated 2 weeks agoView details

Join founders building with open source

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

Subscribe on SubstackJoin 750+ subscribers