agentleFS
go-playgroundgo-playground/validator/CLAUDE.md

validator

CLAUDE.md20k starsChanged 21 months agoMITView on GitHub

github.com/go-playground/validator/v10 — struct and field validation library based on struct tags. The module path ends in /v10; changes must preserve v10 API compatibility. Contributions require test coverage (see .github/CONTRIBUTING.md). Tests live alongside source in the package root (validatortest.go, benchmarkstest.go); run them from the repo root. Non-standard validators and translations are separate packages (./non-standard/validators, ./translations/...) and are included by ./.... The library compiles validation tags into cached execution plans, then runs them against values via reflection. Understanding three layers is enough…

We split this CLAUDE.md into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When adding a new tag: register it in bakedInValidators in baked_in.go, add its description to the table in README.md, and add tests in …

    line 47
  2. Very specific:

    Avoid allocations in the success path — several baked-in validators and the executor reuse pooled buffers (validate.misc, str1, str2).

    line 70
  3. Very specific:

    Don't introduce new top-level exported types without need — most extension happens through Register* methods on Validate.

    line 76

≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Repository

github.com/go-playground/validator/v10 — struct and field validation library based on struct tags. The module path ends in /v10; changes must preserve v10 API compatibility. Contributions require test coverage (see .github/CONTRIBUTING.md).

Commands

make test              # go test -cover -race ./...
make lint              # installs golangci-lint v2.0.2 if missing, then runs it
make bench             # go test -run=NONE -bench=. -benchmem ./...

# Single test / subtest
go test -run TestName ./...
go test -run TestName/subtest_name ./...

# Single benchmark
go test -run=NONE -bench=BenchmarkFieldSuccess -benchmem ./...

Tests live alongside source in the package root (validator_test.go, benchmarks_test.go); run them from the repo root. Non-standard validators and translations are separate packages (./non-standard/validators, ./translations/...) and are included by ./....

Architecture

The library compiles validation tags into cached execution plans, then runs them against values via reflection. Understanding three layers is enough to be productive:

1. Registration & configuration — validator_instance.go

Validate is the singleton entry point. It holds:

  • validations — tag → FuncCtx (the validator functions)
  • aliases — shorthand tag → expanded tag expression
  • customFuncs — reflect.Type → value extractor (for types like sql.NullString or anything implementing the Valuer interface, see doc.go)
  • structLevelFuncs — struct-level validators
  • tagCache and structCache — parsed-tag and parsed-struct caches (critical for performance; Validate is thread-safe and must be used as a singleton)

Options live in options.go (WithRequiredStructEnabled, WithPrivateFieldValidation, etc.). WithRequiredStructEnabled is the forward-compatible default users should adopt before v11.

2. Baked-in validators — baked_in.go

All built-in tags (required, email, uuid, oneof, gt, cross-field eqfield, etc.) are registered here as Func/FuncCtx receiving a FieldLevel (see field_level.go). restrictedTags enumerates names that cannot be overridden. Cross-field validators resolve the other field via fl.GetStructFieldOK* against the parent struct captured in the execution context.

Adjacent data tables:

  • regexes.go, postcode_regexes.go — compiled regexps used by validators
  • country_codes.go, currency_codes.go, language_codes.go — lookup tables

When adding a new tag: register it in bakedInValidators in baked_in.go, add its description to the table in README.md, and add tests in validator_test.go.

3. Execution — validator.go + cache.go

  • cache.go parses struct tags into cField and cTag linked lists once per type and stores them in structCache/tagCache. cTag.typeof (typeDefault, typeOmitEmpty, typeDive, typeStructOnly, typeOr, etc.) tells the executor what to do.
  • validator.go contains the per-call validate struct (pooled via sync.Pool) and the validateStruct / traverseField mutual recursion. ns/actualNs are the accumulated dotted namespaces used in error paths; dive, keys, endkeys push/pop through slices/maps.

Public entry points live on Validate: Struct, StructCtx, StructPartial, StructExcept, StructFiltered, Var, VarWithValue, and their Ctx variants.

Errors

errors.go defines ValidationErrors (a []FieldError) and InvalidValidationError. Per README.md and doc.go, callers type-assert err.(validator.ValidationErrors) after checking err != nil. Only InvalidValidationError signals misuse (e.g. passing a non-struct to Struct).

Struct-level & field-level custom validators

struct_level.go and field_level.go define the contexts passed to user-registered functions. Struct-level validators report errors via StructLevel.ReportError / ReportValidationErrors — they operate on the whole struct instead of a single field.

Translations — translations.go + translations/

Each locale under translations/<locale> registers a human-readable message per tag against a ut.Translator. FieldError.Translate(trans) consumes the registered TranslationFunc. When adding a new tag with a translation, add an entry in each locale package — translations are parallel packages, not a single table.

Non-standard validators — non-standard/validators/

Opt-in validators (NotBlank) users register manually. Keep niche or opinionated validators here rather than expanding baked_in.go.

Performance-sensitive areas

Validation is on the hot path for many users. When touching cache.go, validator.go, or baked_in.go hot functions:

  • Avoid allocations in the success path — several baked-in validators and the executor reuse pooled buffers (validate.misc, str1, str2).
  • Benchmarks in benchmarks_test.go gate regressions; run make bench before and after significant changes and include results in the PR if they move.

Conventions

  • Go module minimum version is pinned in go.mod; don't lower it.
  • Don't introduce new top-level exported types without need — most extension happens through Register* methods on Validate.
  • restrictedTags (in baked_in.go) is intentionally a denylist for aliases and registrations; adding a tag with one of those names will break the parser.
  • Examples live under _examples/ (underscore prefix excludes them from the module build). Keep them runnable as standalone main packages.

Download now (ZIP)

Trending

More talk lately.about the whole repository

Dec 2025: 1 mentionJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 1 mentionMay 2026: 2 mentionsJun 2026: 4 mentionsJul 2026: 2 mentionsAug 2026: 0 mentionsSep 2026: 10 mentionsOct 2026: 4 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the go-playground/validator repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about go-playground/validator

The biggest 5 of 73 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 73

Talked about on GitHub, Stack Overflow, Bluesky and the web (73 times).

On GitHub · 50

45 more on GitHub

On Stack Overflow · 15

10 more on Stack Overflow

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.