{"id":29117207,"url":"https://github.com/Oudwins/zog","last_synced_at":"2025-06-29T11:14:18.573Z","repository":{"id":246613686,"uuid":"818985137","full_name":"Oudwins/zog","owner":"Oudwins","description":"Go with Zod inspired simple schema validation","archived":false,"fork":false,"pushed_at":"2025-06-14T17:22:57.000Z","size":2112,"stargazers_count":869,"open_issues_count":11,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-14T18:27:27.238Z","etag":null,"topics":["error-handling","golang","runtime-validation","schema-validation","templ","translation","validation"],"latest_commit_sha":null,"homepage":"https://zog.dev","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Oudwins.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2024-06-23T12:52:57.000Z","updated_at":"2025-06-14T17:22:45.000Z","dependencies_parsed_at":"2024-06-29T04:40:29.747Z","dependency_job_id":"aafa1d38-ba70-42e5-98da-bc344e2d2790","html_url":"https://github.com/Oudwins/zog","commit_stats":null,"previous_names":["oudwins/zog"],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/Oudwins/zog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oudwins%2Fzog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oudwins%2Fzog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oudwins%2Fzog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oudwins%2Fzog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oudwins","download_url":"https://codeload.github.com/Oudwins/zog/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oudwins%2Fzog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262581514,"owners_count":23331925,"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":["error-handling","golang","runtime-validation","schema-validation","templ","translation","validation"],"created_at":"2025-06-29T11:14:15.383Z","updated_at":"2025-06-29T11:14:18.511Z","avatar_url":"https://github.com/Oudwins.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/Oudwins/zog\"\u003e\n     \u003cimg src=\"https://raw.githubusercontent.com/Oudwins/zog/master/assets/zog-banner.png\" alt=\"Zog, a Zod-like schema parser \u0026 validator\" /\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n# ZOG - A Zod \u0026 Yup like Schema Parser \u0026 Validator for GO\n\n[![Coverage Status](https://coveralls.io/repos/github/Oudwins/zog/badge.svg?branch=master)](https://coveralls.io/github/Oudwins/zog?branch=master)\n[![Go Report Card](https://goreportcard.com/badge/Oudwins/zog)](https://goreportcard.com/report/github.com/Oudwins/zog)\n[![GitHub tag](https://img.shields.io/github/tag/Oudwins/zog?include_prereleases=\u0026sort=semver\u0026color=blue)](https://github.com/Oudwins/zog/releases/)\n\u003ca href=\"https://pkg.go.dev/github.com/Oudwins/zog\"\u003e\u003cimg src=\"https://pkg.go.dev/badge/github.com//github.com/Oudwins/tailwind-merge-go.svg\" alt=\"Go Reference\" /\u003e\u003c/a\u003e\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n[![Mentioned in Awesome Templ](https://awesome.re/mentioned-badge-flat.svg)](https://github.com/templ-go/awesome-templ)\n[![stars - zog](https://img.shields.io/github/stars/Oudwins/zog?style=social)](https://github.com/Oudwins/zog)\n\n[![view - Documentation](https://img.shields.io/badge/view-Documentation-blue?style=for-the-badge)](https://zog.dev)\n\nZog is a schema builder for runtime value parsing and validation. Define a schema, transform a value to match, assert the shape of an existing value, or both. Zog schemas are extremely expressive and allow modeling complex, interdependent validations, or value transformations.\n\nKiller Features:\n\n- Concise yet expressive schema interface, equipped to model simple to complex data models\n- **[Zod](https://github.com/colinhacks/zod)-like API**, use method chaining to build schemas in a typesafe manner\n- **Extensible**: add your own Tests and Schemas\n- **Rich errors** with detailed context, make debugging a breeze\n- **Fast**: Zog is one of the fastest Go validation libraries. We are just behind the goplayground/validator for most of the [govalidbench](https://github.com/Oudwins/govalidbench/tree/master) benchmarks.\n- **Built-in coercion** support for most types\n- Zero dependencies!\n- **Four Helper Packages**\n  - **zenv**: parse environment variables\n  - **zhttp**: parse http forms \u0026 query params\n  - **zjson**: parse json\n  - **i18n**: Opinionated solution to good i18n zog errors\n\n\u003e **API Stability:**\n\u003e\n\u003e - I will consider the API stable when we reach v1.0.0\n\u003e - However, I believe very little API changes will happen from the current implementation. The APIs most likely to change are the **data providers** (please don't make your own if possible use the helpers whose APIs will not change meaningfully) and the z.Ctx most other APIs should remain the same. I could be wrong but I don't expect many breaking changes.\n\u003e - Although we want to keep breaking changes to a minimum, Zog is still in version 0 and will have breaking changes in the minor versions as per semver. So please be careful when upgrading minor versions.\n\n## Introduction\n\n#### **0. Read the docs at [zog.dev](https://zog.dev)**\n\nOr don't, below is the quickstart guide\n\n#### **1 Install**\n\n```bash\ngo get github.com/Oudwins/zog\n```\n\n#### **2 Create a user schema and its struct**\n\n```go\nimport (\n\tz \"github.com/Oudwins/zog\"\n)\n\ntype User struct {\n\tName string\n\tAge  int\n}\n\nvar userSchema = z.Struct(z.Shape{\n\t// its very important that schema keys like \"name\" match the struct field name NOT the input data\n\t\"name\": z.String().Min(3, z.Message(\"Override default message\")).Max(10),\n\t\"age\":  z.Int().GT(18),\n})\n```\n\n#### **3 Validate your schema**\n\n**Using [schema.Parse()](https://zog.dev/core-concepts/parsing)**\n\n```go\nfunc main() {\n\tu := User{}\n\tm := map[string]string{\n\t\t\"name\": \"Zog\",\n\t\t\"age\":  \"\", // won't return an error because fields are optional by default\n\t}\n\terrsMap := userSchema.Parse(m, \u0026u)\n\tif errsMap != nil {\n\t\t// handle errors -\u003e see Errors section\n\t}\n\tu.Name // \"Zog\"\n\t// note that this might look weird but we didn't say age was required so Zog just skipped the empty string and we are left with the uninitialized int\n\t// If we need 0 to be a valid value for age we can use a pointer to an int which will be nil if the value was not present in the input data\n\tu.Age // 0\n}\n```\n\n**Using [schema.Validate()](https://zog.dev/core-concepts/validate)**\n\n```go\nfunc main() {\n\tu := User{\n\t\tName: \"Zog\",\n\t\tAge:  0, // wont return an error because fields are optional by default otherwise it will error\n\t}\n\terrsMap := userSchema.Validate(\u0026u)\n\tif errsMap != nil {\n\t\t// handle errors -\u003e see Errors section\n\t}\n}\n```\n\n#### **4. Its easy to use with http \u0026 json**\n\nThe [zhttp package](https://zog.dev/packages/zhttp) has you covered for JSON, Forms and Query Params, just do:\n\n```go\nimport (\n\tzhttp \"github.com/Oudwins/zog/zhttp\"\n)\n\nerr := userSchema.Parse(zhttp.Request(r), \u0026user)\n```\n\nIf you are receiving json some other way you can use the [zjson package](https://zog.dev/packages/zjson)\n\n```go\nimport (\n\tzjson \"github.com/Oudwins/zog/zjson\"\n)\n\nerr := userSchema.Parse(zjson.Decode(bytes.NewReader(jsonBytes)), \u0026user)\n```\n\n#### **5. Or to validate your environment variables**\n\nThe [zenv package](https://zog.dev/packages/zenv) has you covered, just do:\n\n```go\nimport (\n\tzenv \"github.com/Oudwins/zog/zenv\"\n)\n\nerr := envSchema.Parse(zenv.NewDataProvider(), \u0026envs)\n```\n\n#### **6. You can also parse individual fields**\n\n```go\nvar t = time.Time\nerrsList := Time().Required().Parse(\"2020-01-01T00:00:00Z\", \u0026t)\n```\n\n#### **7 Transform Data without limits**\n\n```go\nvar dest []string\nschema := z.Preprocess(func(data any, ctx z.Ctx) ([]string, error) {\n\ts := data.(string) // don't do this, actually check the type\n\treturn strings.Split(s, \",\"), nil\n}, z.Slice(z.String().Trim().Email().Required()))\nerrs := schema.Parse(\"foo@bar.com,bar@foo.com\", \u0026dest) // dest = [foo@bar.com bar@foo.com]\n```\n\n## Roadmap\n\nThese are some of the things I want to add to zog before v1.0.0\n\n- Support for schema.Clone()\n- support for catch \u0026 default for structs \u0026 slices\n- Struct generation from the schemas\n\n## Support\n\nThe damm domain costs me some outrageous amount like 100$ a year, so if any one wants to help cover that cost through github sponsors that is more than welcome.\n\n## Acknowledgments\n\n- Big thank you to @AlexanderArvidsson for being there to talk about architecture and design decisions. It helped a lot to have someone to bounce ideas off of\n- Credit for all the inspiration goes to /colinhacks/zod \u0026 /jquense/yup\n- Credit for the initial idea goes to anthony (@anthonyGG) -\u003e /anthdm/superkit he made a hacky version of this idea that I used as a starting point, I was never happy with it so I inspired me to rewrite it from scratch. I owe him a lot\n- Credit for the zod logo goes to /colinhacks/zod\n\n## License\n\nThis project is licensed under the MIT License -\nsee the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":["Validation","Go","验证"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOudwins%2Fzog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FOudwins%2Fzog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FOudwins%2Fzog/lists"}