Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aymaneallaoui/zod-go
a Go-based validation library inspired by the popular Zod library in TypeScript
https://github.com/aymaneallaoui/zod-go
go golang golang-library validation validation-error validation-library zod zod-validation
Last synced: 2 days ago
JSON representation
a Go-based validation library inspired by the popular Zod library in TypeScript
- Host: GitHub
- URL: https://github.com/aymaneallaoui/zod-go
- Owner: aymaneallaoui
- Created: 2024-09-12T16:28:30.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-09-14T14:54:26.000Z (3 months ago)
- Last Synced: 2024-11-06T09:13:53.999Z (about 2 months ago)
- Topics: go, golang, golang-library, validation, validation-error, validation-library, zod, zod-validation
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Zod-Go: Schema Validation Library for Go
Zod-Go is a Go-based validation library inspired by the popular Zod library in TypeScript(before you say anything yes i'm a TS soy dev, and i don't use go std lib cry about it + i only use go cuz it's blue like TS). It allows developers to easily define schemas to validate complex data structures, including strings, numbers, arrays(we know it's sLiCeS), maps, and nested objects.
## Features
- **Schema Definitions**: Validate strings, numbers, booleans, arrays(sLiCeS), and nested objects.
- **Custom Error Handling**: Get detailed validation errors with custom messages.
- **Concurrent Validation**: "Improve" performance for large shit through concurrent validation.
- **Optional Fields and Default Values**: Handle optional fields gracefully and set defaults where necessary.## Installation
Install the package using `go get`:
```bash
go get github.com/aymaneallaoui/zod-Go/zod
```## Usage
here's a example of how to use it (it's shit i know but i'm lazy and dumb):
```go
package mainimport (
"fmt"
"github.com/aymaneallaoui/zod-Go/zod/validators"
)func main() {
stringSchema := validators.String().
Min(3).Max(5).Required().
WithMessage("minLength", "This string is too short like arch users!").
WithMessage("maxLength", "This string is too long!")err := stringSchema.Validate("ab")
if err != nil {
fmt.Println("Validation failed:", err.(*zod.ValidationError).ErrorJSON())
}
}```
as you can see (i guess) we validate a string with a minimum length of 3 and a maximum length of 5.
Custom error messages (thanks for a friend for suggesting that) are used for both validation rules.