{"id":18465704,"url":"https://github.com/aymaneallaoui/zod-go","last_synced_at":"2025-09-11T21:04:33.953Z","repository":{"id":256803073,"uuid":"856475024","full_name":"aymaneallaoui/zod-go","owner":"aymaneallaoui","description":"a Go-based validation library inspired by the popular Zod library in TypeScript","archived":false,"fork":false,"pushed_at":"2024-09-14T14:54:26.000Z","size":26,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-25T08:12:09.390Z","etag":null,"topics":["go","golang","golang-library","validation","validation-error","validation-library","zod","zod-validation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aymaneallaoui.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-12T16:28:30.000Z","updated_at":"2024-12-24T10:46:28.000Z","dependencies_parsed_at":"2024-12-25T08:11:11.835Z","dependency_job_id":"d7736e60-7133-4279-a154-b857dcf54f71","html_url":"https://github.com/aymaneallaoui/zod-go","commit_stats":null,"previous_names":["aymaneallaoui/zod-go"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymaneallaoui%2Fzod-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymaneallaoui%2Fzod-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymaneallaoui%2Fzod-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aymaneallaoui%2Fzod-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aymaneallaoui","download_url":"https://codeload.github.com/aymaneallaoui/zod-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239166858,"owners_count":19593097,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","golang-library","validation","validation-error","validation-library","zod","zod-validation"],"created_at":"2024-11-06T09:13:57.139Z","updated_at":"2025-09-11T21:04:33.941Z","avatar_url":"https://github.com/aymaneallaoui.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zod-Go\n\n[![Go CI](https://github.com/aymaneallaoui/zod-go/actions/workflows/go.yml/badge.svg)](https://github.com/aymaneallaoui/zod-go/actions/workflows/go.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/aymaneallaoui/zod-go.svg)](https://pkg.go.dev/github.com/aymaneallaoui/zod-go)\n[![Go Report Card](https://goreportcard.com/badge/github.com/aymaneallaoui/zod-go)](https://goreportcard.com/report/github.com/aymaneallaoui/zod-go)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA TypeScript-inspired schema validation library for Go. Zod-Go provides a fluent, chainable API for validating complex data structures with detailed error reporting and excellent performance.\n\n## Features\n\n- **Fluent API**: Chain validation rules for readable and maintainable code\n- **Rich Data Types**: Support for strings, numbers, booleans, arrays, objects, and maps\n- **Detailed Errors**: Comprehensive error reporting with custom messages and nested validation details\n- **High Performance**: Optimized validation with concurrent processing support\n- **Extensible**: Easy to extend with custom validators and rules\n- **Well Documented**: Comprehensive documentation with examples\n- **Well Tested**: High test coverage with benchmarks\n\n## Installation\n\n```bash\ngo get github.com/aymaneallaoui/zod-go\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/aymaneallaoui/zod-go/zod/validators\"\n)\n\nfunc main() {\n    // String validation\n    schema := validators.String().\n        Min(3).\n        Max(50).\n        Required().\n        WithMessage(\"minLength\", \"Username must be at least 3 characters\").\n        WithMessage(\"maxLength\", \"Username cannot exceed 50 characters\")\n\n    if err := schema.Validate(\"jo\"); err != nil {\n        fmt.Println(\"Validation failed:\", err)\n        // Output: Username must be at least 3 characters\n    }\n\n    // Nested object validation\n    userSchema := validators.Object(map[string]zod.Schema{\n        \"name\": validators.String().Min(2).Required(),\n        \"email\": validators.String().Email().Required(),\n        \"age\": validators.Number().Min(18).Max(120),\n        \"address\": validators.Object(map[string]zod.Schema{\n            \"street\": validators.String().Required(),\n            \"city\": validators.String().Required(),\n            \"zipCode\": validators.String().Pattern(`^\\d{5}$`),\n        }).Required(),\n    })\n\n    user := map[string]interface{}{\n        \"name\": \"John Doe\",\n        \"email\": \"john@example.com\",\n        \"age\": 30,\n        \"address\": map[string]interface{}{\n            \"street\": \"123 Main St\",\n            \"city\": \"New York\",\n            \"zipCode\": \"10001\",\n        },\n    }\n\n    if err := userSchema.Validate(user); err != nil {\n        fmt.Println(\"User validation failed:\", err)\n    } else {\n        fmt.Println(\"User data is valid!\")\n    }\n}\n```\n\n## Validation Types\n\n### String Validation\n\n```go\nschema := validators.String().\n    Min(5).                          // Minimum length\n    Max(100).                        // Maximum length\n    Pattern(`^[a-zA-Z0-9]+$`).      // Regex pattern\n    Email().                         // Email format\n    URL().                           // URL format\n    Required().                      // Non-empty required\n    WithMessage(\"min\", \"Too short\")  // Custom error message\n```\n\n### Number Validation\n\n```go\nschema := validators.Number().\n    Min(0).                          // Minimum value\n    Max(100).                        // Maximum value\n    Integer().                       // Must be integer\n    Positive().                      // Must be positive\n    Required()                       // Required field\n```\n\n### Boolean Validation\n\n```go\nschema := validators.Bool().\n    Required().                      // Required field\n    True()                          // Must be true\n```\n\n### Array Validation\n\n```go\nelementSchema := validators.String().Min(1)\nschema := validators.Array(elementSchema).\n    Min(1).                         // Minimum array length\n    Max(10).                        // Maximum array length\n    Unique()                        // All elements must be unique\n```\n\n### Object Validation\n\n```go\nschema := validators.Object(map[string]zod.Schema{\n    \"name\": validators.String().Required(),\n    \"age\": validators.Number().Min(0),\n    \"tags\": validators.Array(validators.String()),\n}).Strict()  // Reject unknown properties\n```\n\n### Map Validation\n\n```go\nkeySchema := validators.String().Min(1)\nvalueSchema := validators.Number().Min(0)\nschema := validators.Map(keySchema, valueSchema)\n```\n\n## Advanced Features\n\n### Custom Error Messages\n\n```go\nschema := validators.String().\n    Min(8).\n    WithMessage(\"minLength\", \"Password must be at least 8 characters\").\n    Pattern(`[A-Z]`).\n    WithMessage(\"pattern\", \"Password must contain at least one uppercase letter\")\n```\n\n### Concurrent Validation\n\nFor validating large datasets efficiently:\n\n```go\nschemas := []zod.Schema{userSchema, userSchema, userSchema}\ndata := []interface{}{user1, user2, user3}\n\nresults := zod.ValidateConcurrently(schemas, data, 4) // 4 workers\nfor _, result := range results {\n    if !result.IsValid {\n        fmt.Printf(\"Validation error: %v\\n\", result.Error)\n    }\n}\n```\n\n### Optional Fields and Defaults\n\n```go\nschema := validators.Object(map[string]zod.Schema{\n    \"name\": validators.String().Required(),\n    \"role\": validators.String().Default(\"user\"),    // Default value\n    \"bio\": validators.String().Optional(),          // Optional field\n})\n```\n\n### Custom Validators\n\n```go\n// Custom validator function\nemailDomainValidator := func(data interface{}) error {\n    email, ok := data.(string)\n    if !ok {\n        return zod.NewValidationError(\"email\", data, \"must be a string\")\n    }\n    if !strings.HasSuffix(email, \"@company.com\") {\n        return zod.NewValidationError(\"email\", email, \"must be a company email\")\n    }\n    return nil\n}\n\nschema := validators.String().\n    Email().\n    Custom(emailDomainValidator)\n```\n\n## Error Handling\n\nZod-Go provides detailed error information:\n\n```go\nerr := schema.Validate(invalidData)\nif err != nil {\n    validationErr := err.(*zod.ValidationError)\n\n    // Get JSON representation\n    fmt.Println(validationErr.ErrorJSON())\n\n    // Access error details\n    fmt.Printf(\"Field: %s\\n\", validationErr.Field)\n    fmt.Printf(\"Message: %s\\n\", validationErr.Message)\n    fmt.Printf(\"Value: %v\\n\", validationErr.Value)\n\n    // Handle nested errors\n    for _, detail := range validationErr.Details {\n        fmt.Printf(\"Nested error - Field: %s, Message: %s\\n\",\n            detail.Field, detail.Message)\n    }\n}\n```\n\n## Performance\n\nZod-Go is optimized for performance with:\n\n- Zero-allocation validation paths for simple types\n- Concurrent validation for large datasets\n- Efficient memory usage with object pooling\n- Benchmark results show 10x+ performance improvement over reflection-based validators\n\n## Contributing\n\nWe welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.\n\n### Development Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/aymaneallaoui/zod-go.git\ncd zod-go\n\n# Install dependencies\ngo mod tidy\n\n# Run tests\ngo test ./...\n\n# Run benchmarks\ngo test -bench=. ./benchmarks\n\n# Run linter\ngolangci-lint run\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Inspiration\n\nThis library is inspired by [Zod](https://github.com/colinhacks/zod), the popular TypeScript schema validation library.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymaneallaoui%2Fzod-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faymaneallaoui%2Fzod-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymaneallaoui%2Fzod-go/lists"}