Go API Validation
API validation usually needs more than a boolean result. Clients need field paths, readable messages, and predictable JSON output. Valgo builds those results from validation sessions.
Validate a request payload
Section titled “Validate a request payload”Use Is(...) when you want each validator chain to stop after the first failed rule:
val := v.Is( v.String(input.Email, "email").Not().Blank().Email(), v.String(input.Password, "password").Not().Blank().LengthBetween(8, 72),)Use Check(...) when you want to collect multiple messages from the same chain:
val := v.Check( v.String(input.Password, "password").Not().Blank().LengthBetween(8, 72),)Return structured errors
Section titled “Return structured errors”Valgo can convert a validation session to an error, inspect messages, or produce structured output for JSON responses.
if err := val.ToError(); err != nil { return err}See Go Validation Errors and JSON Output for output options and Go Sign-up Form Validation for a complete request-style example.
Nested API payloads
Section titled “Nested API payloads”For nested JSON payloads, use namespaces to create stable paths:
val := v.Is( v.In("address", v.String(input.Address.City, "city").Not().Blank(), ),)For arrays or repeated fields, see Validate Go Slices and Indexed Errors.