spvalidator is a small validation library for Go with direct function-call validators.
package main
import "github.com/yorukot/spvalidator"
func main() {
if err := spvalidator.Email("user@example.com"); err != nil {
panic(err)
}
}Validators return nil on success and *spvalidator.ValidationError on failure.
if err := spvalidator.Required(""); spvalidator.IsValidationError(err) {
// handle validation error
}String values can also use a fluent validation chain.
value, err := spvalidator.String(" 123e4567-e89b-12d3-a456-426614174000 ").
TrimSpace().
Required().
Max(36).
UUID().
Value()Non-string values can use Any.
err := spvalidator.Any(21).
Required().
Gte(18).
Lte(120).
Err()Field validators use exported struct field paths.
type Signup struct {
Password string
Confirm string
}
_ = spvalidator.EqField(Signup{"secret", "secret"}, "Password", "Confirm")The package is independently implemented and aims for practical validation coverage for the supported tags. Very broad standards such as postcode formats, BCP 47, HTML detection, cron syntax, and RFC-perfect URL/domain parsing use documented practical checks rather than exhaustive standard conformance.