{"id":15035191,"url":"https://github.com/ma91n/juv","last_synced_at":"2026-03-15T08:21:30.694Z","repository":{"id":150361072,"uuid":"202881196","full_name":"ma91n/juv","owner":"ma91n","description":"juv is a code generator for using go-validator in JSON Unmarshall.","archived":false,"fork":false,"pushed_at":"2019-08-19T09:20:59.000Z","size":14,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-04-03T21:56:10.567Z","etag":null,"topics":["cli","go","go-cli","go-generate","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ma91n.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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}},"created_at":"2019-08-17T12:57:30.000Z","updated_at":"2024-06-19T07:47:07.629Z","dependencies_parsed_at":"2023-07-27T10:00:05.639Z","dependency_job_id":null,"html_url":"https://github.com/ma91n/juv","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ma91n%2Fjuv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ma91n%2Fjuv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ma91n%2Fjuv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ma91n%2Fjuv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ma91n","download_url":"https://codeload.github.com/ma91n/juv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243384344,"owners_count":20282338,"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":["cli","go","go-cli","go-generate","golang"],"created_at":"2024-09-24T20:27:46.784Z","updated_at":"2025-12-26T08:21:48.362Z","avatar_url":"https://github.com/ma91n.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# juv\njuv is a code generator for using [go-validator](https://github.com/go-playground/validator) in JSON Unmarshall.\n\n## Installation\n\nInstall or upgrade Scaneo with this command.\n\n```bash\ngo get -u github.com/laqiiz/juv\n```\n\n## Usage\n\n```bash\njuv [options] paths...\n```\n\n### Example\n\n```bash\njuv -o model_gen.go example\n```\n\n### Options\n\n```console\n$ juv -h\nUsage of juv:\n  -o string\n        -o is output file name (default \"juv_gen.go\")\n  -output string\n        -output is output file name (default \"juv_gen.go\")\n  -p string\n        -p is package name (default \"current directory\")\n  -package string\n        -package is package name (default \"current directory\")\n```\n\n## Go Generate\n\nIf you want to use juv with go generate, then just add this comment to the top of go file.\n\n```go\n//go:generate juv $GOFILE\npackage models\n\ntype Login struct {\n\t// some fields\n}\n```\n\nNow you can call go generate in package models and model_gen.go will be created.\n\n\n## Motivation\n\ngo-validator is a great library, but it becomes redundant when building HTTP server as follows.\n\n```go\nfunc main() {\n  http.HandleFunc(\"/login\", func(w http.ResponseWriter, r *http.Request) {\n  \tvar login Login\n    if err := json.NewDecoder(r.Body).Decode(\u0026login); err != nil {\n        w.WriteHeader(http.StatusBadRequest)\n        _, _ = w.Write([]byte(err.Error()))\n        return\n    }\n    \n    if err := validator.New().Struct(login); err != nil {\n        w.WriteHeader(http.StatusBadRequest)\n        _, _ = w.Write([]byte(err.Error()))\n        return\n    }\n      \n      // ... some logic ...\n  })\n  \n  log.Fatal(http.ListenAndServe(\":8080\", nil))\n}\n\n\n  // Any logic\n```\n\nIt is possible to simplify by performing validation at the stage of json unmarshall.\n\n```go\nfunc (r *Login) UnmarshalJSON(b []byte) error {\n\ttype Alias Login // avoid stack over flow error\n\tvar a Alias\n\tif err := json.Unmarshal(b, \u0026a); err != nil {\n\t\treturn err\n\t}\n\n\tif err := validator.New().Struct(a); err != nil {\n\t\treturn err\n\t}\n\n\tr.ID = a.ID\n\tr.Pass = a.Pass\n\n\treturn nil\n}\n```\n\nSo 1st code can be simple.\n\n```go\nfunc main() {\n  http.HandleFunc(\"/login\", func(w http.ResponseWriter, r *http.Request) {\n  \t  var login Login\n      if err := json.NewDecoder(r.Body).Decode(\u0026login); err != nil { // JSON Unmarshall and Validate\n        w.WriteHeader(http.StatusBadRequest)\n        _, _ = w.Write([]byte(err.Error()))\n        return\n      }  \n      // ... some logic ...\n  })\n  \n  log.Fatal(http.ListenAndServe(\":8080\", nil))\n}\n````\n\n## License\n\nThis project is licensed under the Apache License 2.0 License - see the [LICENSE](LICENSE) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fma91n%2Fjuv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fma91n%2Fjuv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fma91n%2Fjuv/lists"}