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