Documentation ¶
Overview ¶
Package validator provides utilities to provide a uniform valditation experience.
This validator is adapted from Alex Edwards' "let's go further" book, see https://lets-go-further.alexedwards.net
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Validator ¶
func (*Validator) AddError ¶
AddError adds an error to the validator
Per key only one error message can be added. Additional errors will silently be ignored.
When both err and message are given they are wrapped in a new Error.
Either err or message must given a non-empty value, otherwise the error is silently ignored.
func (*Validator) Check ¶
Check evaluates ok and adds messages if not true.
This can be used to build easy to read list of checks.
v.Check(f.Page > 0, "page", errors.New("invalid param"), "must be greater than zero") v.Check(f.Page <= 10_000_000, "page", nil, "must be a maximum of 10 million")
func (*Validator) ErrorOrNil ¶
ErrorOrNil wraps all the errors in a single error or returns nil