{"id":13786691,"url":"https://github.com/go-the-way/validator","last_synced_at":"2026-01-29T02:48:33.751Z","repository":{"id":140057047,"uuid":"467328269","full_name":"go-the-way/validator","owner":"go-the-way","description":"A lightweight model validator written in Go.","archived":false,"fork":false,"pushed_at":"2022-05-11T07:33:08.000Z","size":126,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-22T13:32:30.276Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/go-the-way.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}},"created_at":"2022-03-08T02:03:57.000Z","updated_at":"2023-09-27T03:53:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"f0f0fb55-9fbf-485c-abe1-900e202f644d","html_url":"https://github.com/go-the-way/validator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-the-way%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-the-way%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-the-way%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-the-way%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-the-way","download_url":"https://codeload.github.com/go-the-way/validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225101368,"owners_count":17421075,"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":[],"created_at":"2024-08-03T19:01:28.592Z","updated_at":"2026-01-29T02:48:28.729Z","avatar_url":"https://github.com/go-the-way.png","language":"Go","funding_links":[],"categories":["Validation","验证"],"sub_categories":["Utility/Miscellaneous","实用程序/Miscellaneous","Fail injection"],"readme":"# validator\n\nA lightweight model validator written in Go.\n\n[![CircleCI](https://circleci.com/gh/go-the-way/validator/tree/main.svg?style=shield)](https://circleci.com/gh/go-the-way/validator/tree/main)\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/go-the-way/validator)\n[![codecov](https://codecov.io/gh/go-the-way/validator/branch/main/graph/badge.svg?token=8MAR3J959H)](https://codecov.io/gh/go-the-way/validator)\n[![Go Report Card](https://goreportcard.com/badge/github.com/go-the-way/validator)](https://goreportcard.com/report/github.com/go-the-way/validator)\n[![GoDoc](https://pkg.go.dev/badge/github.com/go-the-way/validator?status.svg)](https://pkg.go.dev/github.com/go-the-way/validator?tab=doc)\n[![Release](https://img.shields.io/github/release/go-the-way/validator.svg?style=flat-square)](https://github.com/go-the-way/validator/releases)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go#validation)\n\n## Features\n- Supports multiple language.\n\n## quickstart\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tv \"github.com/go-the-way/validator\"\n)\n\nfunc main() {\n\tresult := v.New(\u0026struct {\n\t\tint `validate:\"min(10,fail)\"`\n\t}{}).Validate()\n\tfmt.Println(result.Passed)\n\tfmt.Println(result.Messages())\n}\n```\n\n## Custom validation implementation\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tv \"github.com/go-the-way/validator\"\n\t\"reflect\"\n)\n\nfunc main() {\n\tv.Custom(\"mycustom\", func(value reflect.Value) (bool, string) { return false, \"mycustom validation.\" })\n\tvv := v.New(\u0026struct {\n\t\tName string `validate:\"custom(mycustom)\"`\n\t}{}).Validate()\n\tfmt.Println(vv.Passed)\n\tfmt.Println(vv.Messages())\n}\n```\n\n## Validators\n\n| Name         | Support                                                                         | Example                             | Description                                                                                                                      |\n|--------------|---------------------------------------------------------------------------------|-------------------------------------|----------------------------------------------------------------------------------------------------------------------------------|\n| Min          | `([])(*)uint{8,64}`, `([])(*)int{8,64}`, `([])(*)float{32,64}`                  | validate:\"min(N,invalid)\"           | `Every value` must be `\u003e= N`                                                                                                     |\n| Max          | `([])(*)uint{8,64}`, `([])(*)int{8,64}`, `([])(*)float{32,64}`                  | validate:\"max(N,invalid)\"           | `Every value` must be `\u003c= N`                                                                                                     |\n| Length       | `(*)string`, `(*)Array[(*)string]`, `(*)Slice[(*)string]`                       | validate:\"length(N,invalid)\"        | `(*)string`: `Value's Len` must be `== N`\u003cbr/\u003e`(*)Array[(*)string]` or `(*)Slice[(*)string]`: `Every Value's Len` must be `== N` |\n| ArrLength    | `(*)Array[(*)Any]`, `(*)Slice[(*)Any]`                                          | validate:\"arr_length(N,invalid)\"    | `(*)Array[(*)Any]` or `(*)Slice[(*)Any]`: `Array` or `Slice's Len` must be `== N`                                                |\n| MinLength    | `(*)string`, `(*)Array[(*)string]`, `(*)Slice[(*)string]`                       | validate:\"minlength(N,invalid)\"     | `(*)string`: `Value's Len` must be `\u003e= N`\u003cbr/\u003e`(*)Array[(*)string]` or `(*)Slice[(*)string]`: `Every Value's Len` must be `\u003e= N` |\n| ArrMinLength | `(*)Array[(*)Any]`, `(*)Slice[(*)Any]`                                          | validate:\"arr_minlength(N,invalid)\" | `(*)Array[(*)Any]` or `(*)Slice[(*)Any]`: `Array` or `Slice's Len` must be `\u003e= N`                                                |\n| MaxLength    | `(*)string`, `(*)Array[(*)string]`, `(*)Slice[(*)string]`                       | validate:\"maxlength(N,invalid)\"     | `(*)string`: `Value's Len` must be `\u003c= N`\u003cbr/\u003e`(*)Array[(*)string]` or `(*)Slice[(*)string]`: `Every Value's Len` must be `\u003c= N` |\n| ArrMaxLength | `(*)Array[(*)Any]`, `(*)Slice[(*)Any]`                                          | validate:\"arr_maxlength(N,invalid)\" | `(*)Array[(*)Any]` or `(*)Slice[(*)Any]`: `Array` or `Slice's Len` must be `\u003c= N`                                                |\n| Enum         | `([])(*)uint{8,64}`, `([])(*)int{8,64}`, `([])(*)float{32,64}`, `([])(*)string` | validate:\"enum(O,invalid)\"          | `Every value` must be one of `O`                                                                                                 |\n| Regex        | `([])(*)string`                                                                 | validate:\"regex(RE,invalid)\"        | `Every value` must be match `RE`                                                                                                 |\n| Valid        | `*struct{}`                                                                     | validate:\"valid(T,invalid)\"         | `Value` must be not `nil`                                                                                                        |\n| Custom       | `any`                                                                           | validate:\"custom(CUSTOM)\"           | `CUSTOM` validation                                                                                                       |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-the-way%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-the-way%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-the-way%2Fvalidator/lists"}