Documentation ¶
Overview ¶
Package check provides convenience helpers to perform validations of any kind.
Use That/Thatf to write conditions to check, multiple calls can be chained. The last call in the chain must be FirstError, AllErrors, or JoinErrors.
Example ¶
package main import ( "errors" "fmt" "go-simpler.org/check" ) var user = struct { Name string Age int Email string }{ Name: "", Age: 10, Email: "user@email", } func isEmail(string) bool { return false } var errEmptyName = errors.New("name must not be empty") func main() { err := check. That(user.Name != "", errEmptyName). Thatf(user.Age >= 18, "%d y.o. is too young", user.Age). Thatf(isEmail(user.Email), "%s is invalid email", user.Email). JoinErrors() // or FirstError() / AllErrors(). fmt.Println(err) }
Output: name must not be empty 10 y.o. is too young user@email is invalid email
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type State ¶
type State struct {
// contains filtered or unexported fields
}
State holds the recorded errors. It is exported only for the purpose of documentation.
func Thatf ¶
Thatf checks whether the condition is true, and if not, creates an error from format and args, then records it.
func (*State) FirstError ¶
FirstError returns the first recorded error.
func (*State) JoinErrors ¶ added in v0.4.0
JoinErrors returns all the recorded errors joined via errors.Join.
Click to show internal directories.
Click to hide internal directories.