gitwtfhub

wtf is validator?

go-playground/validator — explained in plain English

Analysis updated 2026-06-21

19,941GoAudience · developerComplexity · 2/5Setup · easy

TL;DR

A Go library that lets you annotate struct fields with simple tags like required or email, then validate all rules at once with a single function call and get detailed error messages per failing field.

Mindmap

mindmap
  root((repo))
    What it does
      Validates struct fields
      Returns error details
      Multi-language errors
    How it works
      Struct tags
      Single validate call
      Cross-field checks
    Supported rules
      Email and URL
      Min and max values
      Custom validators
    Use cases
      API input checks
      Form validation
      Config validation

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Validate user sign-up form fields in a Go web service to check emails, required fields, and password length rules.

REASON 2

Check that API request body structs meet your schema requirements before processing them in a handler.

REASON 3

Write custom validation functions for business rules like confirming a discount code is active or a username is unique.

REASON 4

Validate every element of a list or map field, not just the container, using deep slice and map validation.

What's in the stack?

Go

How it stacks up

go-playground/validatorinancgumus/learngogrpc-ecosystem/grpc-gateway
Stars19,94119,96819,886
LanguageGoGoGo
Setup difficultyeasyeasyhard
Complexity2/51/54/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 30min
License not mentioned in the explanation.

Wtf does this do

The go-playground/validator package is a Go library for validating the contents of data structures. The problem it solves is a common one in any application that accepts input: you need to check that data conforms to your expectations before processing it, that an email address actually looks like an email address, that a required field is not empty, that a number falls within an allowed range, or that two password fields match each other. In Go, data is typically organized into structs (groupings of named fields). This library lets you annotate those struct fields with simple tags in your source code, short labels like "required", "min=1", "max=100", "email", or "url", and then call a single validation function that checks all the rules at once. If any rule fails, the library returns detailed error information identifying exactly which field failed and why. Error messages can be translated into multiple languages. What makes this library particularly capable is its support for cross-field comparisons (checking that one field's value is greater than another's), deep validation inside slices, arrays, and maps (so you can validate every element of a list, not just the list itself), and the ability to define custom validation functions for your own business rules. It ships with a very large set of built-in validators covering string formats, network addresses, numbers, dates, geographic coordinates, financial identifiers like credit card numbers and IBAN codes, and much more. It is also the default validator used by the Gin web framework. You would add this library to any Go service or application that processes user input, form data, API request bodies, or configuration.

Yoink these prompts

Prompt 1
I am using go-playground/validator in my Go API. Show me how to add validation tags to a User struct to require email, a name between 2 and 50 characters, and an age between 18 and 120.
Prompt 2
Using go-playground/validator, write a custom validation function that checks a date string represents a date in the future.
Prompt 3
With go-playground/validator, show me how to validate that a ConfirmPassword field matches the Password field using cross-field comparison tags.
Prompt 4
How do I translate go-playground/validator error messages into Spanish and return them to the user in a Gin handler?

Frequently asked questions

wtf is validator?

A Go library that lets you annotate struct fields with simple tags like required or email, then validate all rules at once with a single function call and get detailed error messages per failing field.

What language is validator written in?

Mainly Go. The stack also includes Go.

What license does validator use?

License not mentioned in the explanation.

How hard is validator to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is validator for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.