Skip to content

go-simpler/check

Repository files navigation

check

checks pkg.go.dev goreportcard codecov

Write any validations declaratively.

📦 Install

go get go-simpler.org/check

📋 Usage

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.

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().