Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.
/ go-val Public archive

Val is a flexible data validation library written in Go

License

Notifications You must be signed in to change notification settings

furvr/go-val

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Val

Val is a theoretical/experimental validation library written in Go. Its primary inteded purpose is validation of user-input data (usually from web forms). It should not (yet) be used in a production context.

Working with Contracts

A contract, in val-speak, is a list of terms ([]Conditions) which must be met. To create a contract, do:

var contract = val.NewContract()

Add rules to a contract with contract.AddRule(*val.Data, val.ValidatorFunc). In the following example val.EqualsString is a built-in validation function which validates that the value contained in the provided data equals the string provided in its first parameter.

var data = NewData([]byte("value"), "DATA-TYPE", "DATA-CATEGORY")
contract.AddRule(data, val.EqualsString("value", "Values are not equal."))

To run validation, call contract.Validate(). The returned boolean indicates whether the contract passed all rules (true) or failed one or more rule (false).

When a contract fails validation, pointers to each failed Condition are provided in contract.Fails.

if ok := contract.Validate(); !ok {
	for _, f := range contract.Fails {
		fmt.Printf("Expected rules to pass; Data with sig `%v` returned errors: %v",
			f.Condition.Data.Signature,
			f.Error)
	}
}

Contributing

Pull-requests are welcome, and so are you. :)

Currently, approved PRs are those which improve performance and documentation, add useful functionality (core lib or built-ins), or fix bugs / flaws.

If you'd like to submit a PR which changes the API, adds currently unrepresented functionality, or modifies existing (stable) behavior, create an issue and reference your pull request so we can talk about it.

These contribution guidelines may be more structured in the future, depending on community reception.

About

Val is a flexible data validation library written in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages