{"id":20017606,"url":"https://github.com/foomo/fender","last_synced_at":"2025-05-04T22:32:00.297Z","repository":{"id":37985948,"uuid":"379923114","full_name":"foomo/fender","owner":"foomo","description":"Opinionated validation library.","archived":false,"fork":false,"pushed_at":"2024-09-09T02:17:04.000Z","size":144,"stargazers_count":4,"open_issues_count":7,"forks_count":0,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-08T13:50:09.482Z","etag":null,"topics":["foomo","foomo-fender","go","golang","validation","validator"],"latest_commit_sha":null,"homepage":"https://www.foomo.org","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/foomo.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":"2021-06-24T12:49:43.000Z","updated_at":"2024-08-24T11:18:17.000Z","dependencies_parsed_at":"2024-04-30T07:47:32.691Z","dependency_job_id":null,"html_url":"https://github.com/foomo/fender","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foomo%2Ffender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foomo%2Ffender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foomo%2Ffender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foomo%2Ffender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foomo","download_url":"https://codeload.github.com/foomo/fender/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252408459,"owners_count":21743124,"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":["foomo","foomo-fender","go","golang","validation","validator"],"created_at":"2024-11-13T08:16:55.030Z","updated_at":"2025-05-04T22:31:59.951Z","avatar_url":"https://github.com/foomo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fender\n\n\u003e a piece of rope or a tyre that protects the side of a boat from knocks\n\nFender provides a unified way to validate data and on the backend \u0026 frontend side.\n\n## Usage\n\n### All\n\n```go\nfunc ExampleAll() {\n\terr := fender.All(\n\t\tcontext.Background(),\n\t\tfend.Field(\"one\", \"\", rule.RequiredString, rule.MinString(10)),\n\t\tfend.Field(\"two\", \"\", rule.RequiredString, rule.MinString(10)),\n\t)\n\t// check for fender error\n\tif fendErr := fender.AsError(err); fendErr != nil {\n\t\tfmt.Println(err)\n\t} else if err != nil {\n\t\tpanic(err)\n\t}\n\t// Output: one:required:min=10;two:required:min=10\n}\n```\n\n### AllFirst\n\n```go\nfunc ExampleAllFirst() {\n\terr := fender.AllFirst(\n\t\tcontext.Background(),\n\t\tfend.Field(\"one\", \"\", rule.RequiredString, rule.MinString(10)),\n\t\tfend.Field(\"two\", \"\", rule.RequiredString, rule.MinString(10)),\n\t)\n\n\t// check for fender error\n\tif fendErr := fender.AsError(err); fendErr != nil {\n\t\tfmt.Println(err)\n\t} else if err != nil {\n\t\tpanic(err)\n\t}\n\t// Output: one:required:min=10\n}\n```\n\n### First\n\n```go\nfunc ExampleFirst() {\n\terr := fender.First(\n\t\tcontext.Background(),\n\t\tfend.Field(\"one\", \"\", rule.RequiredString, rule.MinString(10)),\n\t\tfend.Field(\"two\", \"\", rule.RequiredString, rule.MinString(10)),\n\t)\n\n\t// check for fender error\n\tif fendErr := fender.AsError(err); fendErr != nil {\n\t\tfmt.Println(err)\n\t} else if err != nil {\n\t\tpanic(err)\n\t}\n\t// Output: one:required\n}\n```\n\n### Handle errors\n\n```go\nfunc ExampleErrors() {\n\terr := fender.All(\n\t\tcontext.Background(),\n\t\tfend.Field(\"one\", \"\", rule.RequiredString, rule.MinString(10)),\n\t\tfend.Field(\"two\", \"\", rule.RequiredString, rule.MinString(10)),\n\t)\n\n\t// cast fender error\n\tif fenderErr := fender.AsError(err); fenderErr != nil {\n\n\t\t// iterate fend errors\n\t\tfor _, err := range fenderErr.Errors() {\n\n\t\t\t// cast fend error\n\t\t\tif fendErr := fend.AsError(err); fendErr != nil {\n\n\t\t\t\tfmt.Println(fendErr.Name())\n\n\t\t\t\t// iterate rule errors\n\t\t\t\tfor _, err := range fendErr.Errors() {\n\n\t\t\t\t\t// cast rule error\n\t\t\t\t\tif ruleErr := rule.AsError(err); ruleErr != nil {\n\t\t\t\t\t\tfmt.Println(ruleErr.Error())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else if err != nil {\n\t\tpanic(err)\n\t}\n\t// Output:\n\t// one\n\t// required\n\t// min=10\n\t// two\n\t// required\n\t// min=10\n}\n```\n\n## Benchmarks\n\n```text\ngo test -bench=. | prettybench\ngoos: darwin\ngoarch: arm64\npkg: github.com/foomo/fender\nPASS\nbenchmark                                      iter       time/iter\n---------                                      ----       ---------\nBenchmarkAll/invalid_reused/fender-10        282154   3771.00 ns/op\nBenchmarkAll/invalid_reused/playground-10    678679   1741.00 ns/op\nBenchmarkAll/success_new/fender-10          1000000   1026.00 ns/op\nBenchmarkAll/success_new/playground-10      1308327    937.60 ns/op\nok  \tgithub.com/foomo/fender\t5.619s\n```\n\n## References \u0026 alternatives\n\n- [go-playground/validator](https://github.com/go-playground/validator)\n- [go-ozzo/ozzo-validation](https://github.com/go-ozzo/ozzo-validation)\n\n## How to Contribute\n\nMake a pull request...\n\n## License\n\nDistributed under MIT License, please see license file within the code for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoomo%2Ffender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoomo%2Ffender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoomo%2Ffender/lists"}