From ad7593495482cdca706fd16fe57d1618d06ea45a Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Fri, 21 Jun 2024 21:54:44 +0100 Subject: [PATCH] add readme for each package --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b2929b --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Go Validate + +A suite of straightforward validation functions. You put something in, you get back `nil` or an error. + +## Error handling + +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: + +## Example + +```go +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") + } + } +} +``` + +## License + +See [LICENSE.md](../LICENSE.md)