Branch | Status | Coverage |
---|---|---|
master |
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.
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{...},
// }
}
Hyperscale Validator is licensed under the MIT license.