add Required, Prefix, Suffix, Contains, Match validators #9

Merged
aneurin merged 1 commits from expand-validators into main 2026-09-07 12:51:43 +00:00
Member

First, conservative expansion of the built-in set (see #6), all in the existing style — constructor returning func(T) error, sentinel error matched with errors.Is, table-driven tests plus an Example:

Validator Checks
Required[T comparable]() value is not the zero value
Prefix(p) / Suffix(s) / Contains(sub) strings.HasPrefix / HasSuffix / Contains
Match(re *regexp.Regexp) string matches the pattern

New files: required.go, string.go, match.go (+ tests). No dependencies added, no changes to existing files. go vet + go test ./... green.

Further candidates (Between, NotBlank, OneOf, IP/CIDR, time bounds, …) are listed in #6 for triage rather than dumped here.

Closes #6

🤖 Generated with Claude Code

First, conservative expansion of the built-in set (see #6), all in the existing style — constructor returning `func(T) error`, sentinel error matched with `errors.Is`, table-driven tests plus an `Example`: | Validator | Checks | |---|---| | `Required[T comparable]()` | value is not the zero value | | `Prefix(p)` / `Suffix(s)` / `Contains(sub)` | `strings.HasPrefix` / `HasSuffix` / `Contains` | | `Match(re *regexp.Regexp)` | string matches the pattern | New files: `required.go`, `string.go`, `match.go` (+ tests). No dependencies added, no changes to existing files. `go vet` + `go test ./...` green. Further candidates (`Between`, `NotBlank`, `OneOf`, `IP`/`CIDR`, time bounds, …) are listed in #6 for triage rather than dumped here. Closes #6 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-09-07 12:23:08 +00:00
Broadens the built-in set with the string/presence checks that came up
most often when reaching for this package:

  - Required[T comparable]  non-zero value
  - Prefix / Suffix / Contains  strings.HasPrefix/HasSuffix/Contains
  - Match(*regexp.Regexp)  arbitrary pattern

All follow the existing shape: a constructor returning func(T) error, a
sentinel error matched with errors.Is, table-driven tests and an Example.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
aneurin merged commit 82611a5e96 into main 2026-09-07 12:51:43 +00:00
aneurin deleted branch expand-validators 2026-09-07 12:51:43 +00:00
Sign in to join this conversation.