Skip to content

SLASH2NL/validate

Repository files navigation

Golang validation library

Validate is a simple golang validation library that is focussed on simplicity and typed validators.

GoDev

Usage

See examples_test.go for usage.

Creating custom validators

A validator is a simple function that takes a value and returns an error if the value is invalid. If the error is a violation it should return a validate.Violation error. If the error is an exception that should be handled by the caller it should return a normal error.

// Returns an error if the number is not 42.
func Is42(x int) error {
    if x != 42 {
        return &validate.Violdation{ Code: "Is42" }
    }

    return nil
}

About

A simple typed validation library for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages