This minimal library allows to embrace Fail Fast paradigm, by providing a set of functions to check preconditions and do validations on arguments. Whenever a precondition is not met, a panic will be thrown.
Just get it
$ go get github.com/raulbajales/go-argcheck/argcheck
And use it
import (
"github.com/raulbajales/go-argcheck/argcheck"
"fmt"
)
func calculateMonthlySalary(total int, numMonths int) int {
argcheck.GreaterThanf(numMonths, 0, "numMonths must be positive and not zero, numMonths is %v", numMonths)
return total / numMonths
}
func main() {
total := 50000
numMonths := 0
fmt.Printf("Total salary of %v in %v months, gives %v per month.", total, numMonths, calculateMonthlySalary(total, numMonths))
}
Check GoDoc here for more preconditions/validations.