Validate input data in Go https://pkg.go.dev/github.com/annybs/go-validate
|
11 meses atrás | |
---|---|---|
LICENSE.md | 11 meses atrás | |
README.md | 11 meses atrás | |
all.go | 1 ano atrás | |
all_test.go | 1 ano atrás | |
chars.go | 1 ano atrás | |
chars_test.go | 1 ano atrás | |
email.go | 1 ano atrás | |
email_test.go | 1 ano atrás | |
equal.go | 1 ano atrás | |
equal_test.go | 1 ano atrás | |
error.go | 1 ano atrás | |
error_test.go | 1 ano atrás | |
go.mod | 1 ano atrás | |
in.go | 1 ano atrás | |
in_test.go | 1 ano atrás | |
length.go | 1 ano atrás | |
length_test.go | 1 ano atrás | |
number.go | 1 ano atrás | |
number_test.go | 1 ano atrás | |
size.go | 1 ano atrás | |
size_test.go | 1 ano atrás | |
url.go | 1 ano atrás | |
url_test.go | 1 ano atrás | |
uuid.go | 1 ano atrás | |
uuid_test.go | 1 ano atrás |
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