A Go library for validating structs and fields.
-
Simple
Simple and stupid, no magic involved.
-
Type-safe
Schema is defined in Go, which is type-safer (and more powerful) than traditional struct tags.
-
Flexible
- Validators are composite.
- Nested struct validation is well supported.
- Schema can be defined inside or outside struct.
- Validator customizations are made easy.
-
No reflection
$ go get github.com/RussellLuo/validating
To be strict, this library has a conceptual distinction between validator factory
and validator
.
A validator factory is a function to create a validator, which will do the actual validation.
- Single field
- Flag field
- Simple struct
- Nested struct
- Nested struct (schema inside)
- Nested struct pointer
- Nested struct slice
- Nested struct map
Check out the Godoc.
This library borrows some ideas from the following libraries:
-
Prefer no reflection.
-
Support composite-style validator factories
All
/And
,Any
/Or
. -
Use the term
nonzero
instead ofrequired
/optional
.