{"id":43761036,"url":"https://github.com/goflash/validator","last_synced_at":"2026-02-05T15:06:02.660Z","repository":{"id":311495060,"uuid":"1043684000","full_name":"goflash/validator","owner":"goflash","description":"Validation helpers and i18n middleware for the GoFlash framework","archived":false,"fork":false,"pushed_at":"2025-09-02T04:11:02.000Z","size":35,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-28T04:59:56.041Z","etag":null,"topics":["framework","go","goflash","i18n","validation"],"latest_commit_sha":null,"homepage":"https://goflash.dev","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/goflash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"patreon":"meshin"}},"created_at":"2025-08-24T11:59:29.000Z","updated_at":"2025-08-25T14:44:28.000Z","dependencies_parsed_at":"2025-08-24T23:37:10.168Z","dependency_job_id":null,"html_url":"https://github.com/goflash/validator","commit_stats":null,"previous_names":["goflash/validator"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/goflash/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goflash%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goflash%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goflash%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goflash%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goflash","download_url":"https://codeload.github.com/goflash/validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goflash%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29124793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T14:05:12.718Z","status":"ssl_error","status_checked_at":"2026-02-05T14:03:53.078Z","response_time":65,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["framework","go","goflash","i18n","validation"],"created_at":"2026-02-05T15:06:02.205Z","updated_at":"2026-02-05T15:06:02.653Z","avatar_url":"https://github.com/goflash.png","language":"Go","readme":"# Validation helpers and i18n middleware for the GoFlash framework\n\n\u003ch1 align=\"center\"\u003e\n    \u003ca href=\"https://pkg.go.dev/github.com/goflash/validator/v2@v2.0.1\"\u003e\n        \u003cimg src=\"https://pkg.go.dev/badge/github.com/goflash/validator.svg\" alt=\"Go Reference\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://goreportcard.com/report/github.com/goflash/validator\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/%F0%9F%93%9D%20Go%20Report-A%2B-75C46B?style=flat-square\" alt=\"Go Report Card\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/goflash/validator\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/goflash/validator/graph/badge.svg\" alt=\"Coverage\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/goflash/validator/actions?query=workflow%3ATest\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/goflash/validator/test-coverage.yml?branch=main\u0026label=%F0%9F%A7%AA%20Tests\u0026style=flat-square\u0026color=75C46B\" alt=\"Tests\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/go-1.23%2B-00ADD8?logo=golang\" alt=\"Go Version\"\u003e\n    \u003ca href=\"https://docs.goflash.dev\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/%F0%9F%92%A1%20GoFlash-docs-00ACD7.svg?style=flat-square\" alt=\"GoFlash Docs\"\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/status-stable-green\" alt=\"Status\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue\" alt=\"License\"\u003e\n    \u003cbr\u003e\n    \u003cdiv style=\"text-align:center\"\u003e\n      \u003ca href=\"https://discord.gg/QHhGHtjjQG\"\u003e\n        \u003cimg src=\"https://dcbadge.limes.pink/api/server/https://discord.gg/QHhGHtjjQG\" alt=\"Discord\"\u003e\n      \u003c/a\u003e\n    \u003c/div\u003e\n\u003c/h1\u003e\n\nLightweight validation helpers powered by go-playground/validator and a tiny i18n middleware for the GoFlash framework. It gives you a ready-to-use validator instance, helper mappers to field-\u003emessage maps, and a middleware to plug app-level translations without pulling locale packages into the framework.\n\n## Features\n\n- Uses github.com/go-playground/validator/v10 under the hood\n- Global validate.Validator with JSON tag name support out of the box\n- Helpers to map validator.ValidationErrors into map[field]message\n- Pluggable message function: global or per-request via context\n- i18n middleware that wires your translators in one place\n\n## Installation\n\n```sh\ngo get github.com/goflash/validator/v2\n```\n\nGo version: requires Go 1.23+. The module sets `go 1.23` and can be used with newer Go versions. If you use `GOTOOLCHAIN=auto`, the `toolchain` directive will ensure a compatible toolchain is used.\n\n## Quick start\n\n```go\nimport (\n    \"github.com/goflash/flash/v2\"\n    \"github.com/goflash/validator/v2/validate\"\n)\n\ntype User struct {\n    Name string `json:\"name\" validate:\"required,min=2\"`\n    Age  int    `json:\"age\"  validate:\"gte=0,lte=130\"`\n}\n\nfunc main() {\n    a := flash.New()\n    a.POST(\"/users\", func(c flash.Ctx) error {\n        var u User\n        if err := c.BindJSON(\u0026u); err != nil {\n            return c.JSON(map[string]any{\"message\": \"invalid payload\", \"error\": err.Error()})\n        }\n        if err := validate.Struct(u); err != nil {\n            return c.JSON(map[string]any{\"message\": \"validation failed\", \"fields\": validate.ToFieldErrors(err)})\n        }\n        return c.JSON(u)\n    })\n}\n```\n\n## Configuration\n\nUse ValidatorI18n to attach localized messages per request:\n\n```go\nimport (\n    \"github.com/goflash/flash/v2\"\n    v10 \"github.com/go-playground/validator/v10\"\n    \"github.com/goflash/validator/v2/validate\"\n    mw \"github.com/goflash/validator/v2\"\n)\n\napp := flash.New()\napp.Use(mw.ValidatorI18n(mw.ValidatorI18nConfig{\n    DefaultLocale: \"en\",\n    MessageFuncFor: func(locale string) func(v10.FieldError) string {\n        // Look up your translator for the locale and return fe.Translate(trans)\n        return func(fe v10.FieldError) string { return fe.Error() }\n    },\n    SetGlobal: true, // optionally set global fallback to DefaultLocale\n}))\n```\n\n### Messages and mapping\n\n- Register custom tags and tag-name functions directly on `validate.Validator`.\n- Map errors with `validate.ToFieldErrors(err)` or `validate.ToFieldErrorsWithContext(ctx, err)`.\n- Provide request-scoped message function via middleware or `validate.WithMessageFunc(ctx, fn)`.\n\n### Default messages\n\nBuilt-in minimal fallback messages cover common tags like required, min/max/len, email, oneof, gte/lte, url, uuid, alpha/alphanum/numeric, contains/excludes, startswith/endswith, base64, json, ip/cidr, ascii/printascii/multibyte, isbn/isbn10/isbn13.\n\n### Context\n\nThe middleware stores a request-scoped message function on the request context. Use `validate.MessageFuncFromContext(c.Context())` to retrieve it if needed.\n\n### Errors\n\nWhen mapping errors, non-validation errors are returned under the `_error` key. You can also pass your own `validate.FieldErrors` map.\n\n## Examples\n\nThree runnable examples are included:\n\n- examples/binding_json: simple JSON bind and respond\n- examples/validation: struct validation and error mapping\n- examples/validation_with_i18n: localized messages using the middleware\n\nTry them locally (they use this module):\n\n```sh\ncd ../validation \u0026\u0026 go run .\ncd ../validation_with_i18n \u0026\u0026 go run .\n```\n\n## Versioning and compatibility\n\n- Module path: `github.com/goflash/validator/v2`\n- Requires Go 1.23+\n- Versioning starts at v2.0.0\n\n## Contributing\n\nIssues and PRs are welcome. Please run tests before submitting:\n\n```sh\ngo test ./...\n```\n\n## License\n\nMIT\n","funding_links":["https://patreon.com/meshin"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoflash%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoflash%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoflash%2Fvalidator/lists"}