{"id":18787914,"url":"https://github.com/wuhan005/govalid","last_synced_at":"2025-04-13T13:20:24.131Z","repository":{"id":43352889,"uuid":"248290263","full_name":"wuhan005/govalid","owner":"wuhan005","description":"一直没有好用的表单验证库，索性写一个自己用。/ A simple Go form validator.","archived":false,"fork":false,"pushed_at":"2024-09-03T08:00:22.000Z","size":106,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T04:22:20.049Z","etag":null,"topics":["form-validator","go","validation"],"latest_commit_sha":null,"homepage":"","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/wuhan005.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"wuhan005"}},"created_at":"2020-03-18T16:53:12.000Z","updated_at":"2024-09-03T07:58:20.000Z","dependencies_parsed_at":"2024-02-21T08:27:56.378Z","dependency_job_id":"ef0fc1f7-1d93-4f5c-838a-d31e6d33923d","html_url":"https://github.com/wuhan005/govalid","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuhan005%2Fgovalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuhan005%2Fgovalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuhan005%2Fgovalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wuhan005%2Fgovalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wuhan005","download_url":"https://codeload.github.com/wuhan005/govalid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717960,"owners_count":21150482,"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":["form-validator","go","validation"],"created_at":"2024-11-07T20:56:59.699Z","updated_at":"2025-04-13T13:20:24.052Z","avatar_url":"https://github.com/wuhan005.png","language":"Go","funding_links":["https://github.com/sponsors/wuhan005"],"categories":[],"sub_categories":[],"readme":"# govalid\n\nA simple Go struct validator.\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/wuhan005/govalid)](https://goreportcard.com/report/github.com/wuhan005/govalid)\n\n## Quick Start\n\n```bash\ngo get -u github.com/wuhan005/govalid\n```\n\n```go\nv := struct {\n    Name string `valid:\"required;username\" label:\"昵称\"`\n    ID   int    `valid:\"required;min:0;max:999\" label:\"用户编号\"`\n    Mail string `valid:\"required;email\" label:\"\"`\n}{\n    \"e99_\", 1990, \"i@github.red.\",\n}\n\nerrs, ok := govalid.Check(v)\nif !ok {\n    for _, err := range errs {\n        fmt.Println(err)\n    }\n}\n```\n\nOutput:\n\n```text\n昵称的最后一个字符不能为下划线\n用户编号应小于999\n不是合法的电子邮箱格式\n```\n\n## Customize Error Message\n\n```go\ngovalid.SetMessageTemplates(map[string]string{\n    \"required\": \"can't be null.\",\n    \"min\": \"must bigger than %v.\",\n})\n```\n\n## Customize Error Check Function\n\n```go\nfunc main() {\n\t// set your error message.\n\tgovalid.SetMessageTemplates(map[string]string{\n\t\t\"mycheck\": \"content cann't contain 'e99'.\",\n\t})\n\n\t// add new check function\n\tgovalid.Checkers[\"mycheck\"] = func(c govalid.CheckerContext) *govalid.ErrContext {\n\t\terrCtx := govalid.NewErrorContext(c)\n\t\tvalue, ok := ctx.Value.(string)\n\t\tif !ok {\n\t\t\treturn MakeCheckerParamError(c)\n\t\t}\n\t\tif strings.Contains(value, \"e99\") {\n\t\t\treturn ctx\n\t\t}\n\t\t// if the check passed, return nil.\n\t\treturn nil\n\t}\n\n\tr := struct {\n\t\tContent string `valid:\"mycheck\"`\n\t}{\n\t\t\"helloe99\",\n\t}\n\n    errs, ok := govalid.Check(v)\n    if !ok {\n        for _, err := range errs {\n            fmt.Println(err)\n        }\n    }\n}\n```\n\n## Special Thanks\n\nhttps://github.com/jiazhoulvke/echo-form\n\n## LICENSE\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuhan005%2Fgovalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwuhan005%2Fgovalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwuhan005%2Fgovalid/lists"}