Skip to content

raulbajales/go-argcheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-argcheck

Simple Go argument preconditions checker

GoDoc Build Status

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.

Usage

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.

~ Made with

About

Simple Go argument preconditions checker

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages