Skip to content

The Hyperscale Validator library provides a set of commonly needed data validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.

License

hyperscale-stack/validator

Repository files navigation

Hyperscale Validator Last release Documentation

Go Report Card

Branch Status Coverage
master Build Status Coveralls

The Hyperscale Validator library provides a set of commonly needed data validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.

Example

Validate by map[string]interface{}

package main

import (
    "fmt"
    "github.com/hyperscale-stack/validator"
)

func main() {
    i := NewInputValidator(map[string][]Validator{
		"email": {
			NewEmailValidator(EmailTimeout(1 * time.Second)),
		},
	})

	errs := i.ValidateMap(map[string]interface{}{
		"email":  "bad",
    })
    // return 
    // map[string][]error{
	//     "email": []error{...},
    // }
}

Validate by url.Values

package main

import (
    "fmt"
    "github.com/hyperscale-stack/validator"
)

func main() {
    i := NewInputValidator(map[string][]Validator{
		"email": {
			NewEmailValidator(EmailTimeout(1 * time.Second)),
		},
	})

    values := url.Values{}
    values.Set("email", "bad")

	errs := i.ValidateValues(values)
    // return 
    // map[string][]error{
	//     "email": []error{...},
    // }
}

License

Hyperscale Validator is licensed under the MIT license.

About

The Hyperscale Validator library provides a set of commonly needed data validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published