Validate input data in Go https://pkg.go.dev/github.com/annybs/go-validate
|
hace 11 meses | |
---|---|---|
LICENSE.md | hace 11 meses | |
README.md | hace 11 meses | |
all.go | hace 1 año | |
all_test.go | hace 1 año | |
chars.go | hace 1 año | |
chars_test.go | hace 1 año | |
email.go | hace 1 año | |
email_test.go | hace 1 año | |
equal.go | hace 1 año | |
equal_test.go | hace 1 año | |
error.go | hace 1 año | |
error_test.go | hace 1 año | |
go.mod | hace 1 año | |
in.go | hace 1 año | |
in_test.go | hace 1 año | |
length.go | hace 1 año | |
length_test.go | hace 1 año | |
number.go | hace 1 año | |
number_test.go | hace 1 año | |
size.go | hace 1 año | |
size_test.go | hace 1 año | |
url.go | hace 1 año | |
url_test.go | hace 1 año | |
uuid.go | hace 1 año | |
uuid_test.go | hace 1 año |
A suite of straightforward validation functions. You put something in, you get back nil
or an error.
You can use errors.Is()
to ascertain the type of errors thrown by validation functions. This may be helpful to control side effects, particularly if using multiple validators and returning early (similar to a strongly-typed try-catch). For example:
package main
import (
"errors"
"fmt"
"github.com/annybs/go/validate"
)
func main() {
v := validate.Equal("a")
if err := v("b"); err != nil {
if errors.Is(err, validate.ErrNotEqual) {
fmt.Println("failed successfully")
} else {
fmt.Println("failed unsuccessfully")
}
}
}
See LICENSE.md