{"id":46064463,"url":"https://github.com/gowww/check","last_synced_at":"2026-03-01T12:06:05.863Z","repository":{"id":57499506,"uuid":"96366942","full_name":"gowww/check","owner":"gowww","description":"👮‍♂️ Form validation utilities","archived":false,"fork":false,"pushed_at":"2020-09-12T12:29:20.000Z","size":46,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-14T06:02:10.705Z","etag":null,"topics":["check","checker","error","form","go","golang","http","valid","validation","validator","value"],"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/gowww.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}},"created_at":"2017-07-05T22:42:25.000Z","updated_at":"2020-09-12T12:29:22.000Z","dependencies_parsed_at":"2022-08-28T14:02:07.212Z","dependency_job_id":null,"html_url":"https://github.com/gowww/check","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gowww/check","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowww%2Fcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowww%2Fcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowww%2Fcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowww%2Fcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gowww","download_url":"https://codeload.github.com/gowww/check/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gowww%2Fcheck/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29969243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T11:43:06.159Z","status":"ssl_error","status_checked_at":"2026-03-01T11:43:03.887Z","response_time":124,"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":["check","checker","error","form","go","golang","http","valid","validation","validator","value"],"created_at":"2026-03-01T12:06:01.719Z","updated_at":"2026-03-01T12:06:05.842Z","avatar_url":"https://github.com/gowww.png","language":"Go","readme":"# [![gowww](https://avatars.githubusercontent.com/u/18078923?s=20)](https://github.com/gowww) check [![GoDoc](https://godoc.org/github.com/gowww/check?status.svg)](https://godoc.org/github.com/gowww/check) [![Build](https://travis-ci.org/gowww/check.svg?branch=master)](https://travis-ci.org/gowww/check) [![Coverage](https://coveralls.io/repos/github/gowww/check/badge.svg?branch=master)](https://coveralls.io/github/gowww/check?branch=master) [![Go Report](https://goreportcard.com/badge/github.com/gowww/check)](https://goreportcard.com/report/github.com/gowww/check) ![Status Testing](https://img.shields.io/badge/status-testing-orange.svg)\n\nPackage [check](https://godoc.org/github.com/gowww/check) provides request form checking.\n\n- [Installing](#installing)\n- [Usage](#usage)\n\t- [JSON](#json)\n\t- [Internationalization](#internationalization)\n\t- [Rules](#rules)\n\n## Installing\n\n1. Get package:\n\n\t```Shell\n\tgo get -u github.com/gowww/check\n\t```\n\n2. Import it in your code:\n\n\t```Go\n\timport \"github.com/gowww/check\"\n\t```\n\n## Usage\n\n1. Make a [Checker](https://godoc.org/github.com/gowww/check#Checker) with [rules](#rules) for keys:\n\n\t```Go\n\tuserChecker := check.Checker{\n\t\t\"email\":   {check.Required, check.Email, check.Unique(db, \"users\", \"email\", \"?\")},\n\t\t\"phone\":   {check.Phone},\n\t\t\"picture\": {check.MaxFileSize(5000000), check.Image},\n\t}\n\t```\n\n\tThe rules order is significant so for example, it's smarter to check the format of a value before its uniqueness, avoiding some useless database requests.\n\n2. Check data:\n\n\t- From a values map, with [Checker.CheckValues](https://godoc.org/github.com/gowww/check#Checker.CheckValues):\n\n\t\t```Go\n\t\terrs := userChecker.CheckValues(map[string][]string{\n\t\t\t\"name\":  {\"foobar\"},\n\t\t\t\"phone\": {\"0012345678901\"},\n\t\t})\n\t\t```\n\n\t- From an [http.Request](https://golang.org/pkg/net/http/#Request), with [Checker.CheckRequest](https://godoc.org/github.com/gowww/check#Checker.CheckRequest):\n\n\t\t```Go\n\t\terrs := userChecker.CheckRequest(r)\n\t\t```\n\n3. Handle errors:\n\n\t```Go\n\tif errs.NotEmpty() {\n\t\tfmt.Println(errs)\n\t}\n\t```\n\n### JSON\n\nUse [Errors.JSON](https://godoc.org/github.com/gowww/check#Errors.JSON) to get errors in a map under `errors` key, ready to be JSON formatted (as an HTTP API response, for example):\n\n```Go\nif errs.NotEmpty() {\n\terrsjs, _ := json.Marshal(errs.JSON())\n\tw.Write(errsjs)\n}\n```\n\n### Internationalization\n\nInternationalization is handled by [gowww/i18n](https://godoc.org/github.com/gowww/i18n) and there are [built-in translations](https://godoc.org/github.com/gowww/check#pkg-variables) for all errors.\n\nUse [Errors.T](https://godoc.org/github.com/gowww/check#Errors.T) with an [i18n.Translator](https://godoc.org/github.com/gowww/i18n#Translator) (usually stored in the request context) to get translated errors:\n\n```Go\nif errs.NotEmpty() {\n\ttransErrs := errs.T(i18n.RequestTranslator(r))\n\tfmt.Println(transErrs)\n}\n```\n\nYou can provide custom translations for each error type under keys like \"`error` + RuleName\":\n\n```Go\nvar locales = i18n.Locales{\n\tlanguage.English: {\n\t\t\"hello\": \"Hello!\",\n\n\t\t\"errorMaxFileSize\": \"File too big (%v max.)\",\n\t\t\"errorRequired\":    \"Required field\",\n\t},\n}\n```\n\nIf the [i18n.Translator](https://godoc.org/github.com/gowww/i18n#Translator) is `nil` or a custom translation is not found, the built-in translation of error is used.\n\n### Rules\n\nFunction                                                            | Usage                               | Possible errors\n--------------------------------------------------------------------|-------------------------------------|------------------------------------\n[Alpha](https://godoc.org/github.com/gowww/check#Alpha)             | `Alpha`                             | `notAlpha`\n[Email](https://godoc.org/github.com/gowww/check#Email)             | `Email`                             | `notEmail`\n[FileType](https://godoc.org/github.com/gowww/check#FileType)       | `FileType(\"text/plain\")`            | `badFileType:text/plain`\n[Image](https://godoc.org/github.com/gowww/check#Image)             | `Image`                             | `notImage`\n[Integer](https://godoc.org/github.com/gowww/check#Integer)         | `Integer`                           | `notInteger`\n[Latitude](https://godoc.org/github.com/gowww/check#Latitude)       | `Latitude`                          | `notLatitude`, `notNumber`\n[Longitude](https://godoc.org/github.com/gowww/check#Longitude)     | `Longitude`                         | `notLongitude`, `notNumber`\n[Max](https://godoc.org/github.com/gowww/check#Max)                 | `Max(1)`                            | `max:1`, `notNumber`\n[MaxFileSize](https://godoc.org/github.com/gowww/check#MaxFileSize) | `MaxFileSize(5000000)`              | `maxFileSize:5000000`\n[MaxLen](https://godoc.org/github.com/gowww/check#MaxLen)           | `MaxLen(1)`                         | `maxLen:1`, `notNumber`\n[Min](https://godoc.org/github.com/gowww/check#Min)                 | `Min(1)`                            | `min:1`, `notNumber`\n[MinFileSize](https://godoc.org/github.com/gowww/check#MinFileSize) | `MinFileSize(10)`                   | `minFileSize:10`\n[MinLen](https://godoc.org/github.com/gowww/check#MinLen)           | `MinLen(1)`                         | `minLen:1`, `notNumber`\n[Number](https://godoc.org/github.com/gowww/check#Number)           | `Number`                            | `notNumber`\n[Phone](https://godoc.org/github.com/gowww/check#Phone)             | `Phone`                             | `notPhone`\n[Range](https://godoc.org/github.com/gowww/check#Range)             | `Range(1, 5)`                       | `max:5`, `min:1`, `notNumber`\n[RangeLen](https://godoc.org/github.com/gowww/check#RangeLen)       | `RangeLen(1, 5)`                    | `maxLen:5`, `minLen:1`\n[Required](https://godoc.org/github.com/gowww/check#Required)       | `Required`                          | `required`\n[Same](https://godoc.org/github.com/gowww/check#Same)               | `Same(\"key1\", \"key2\")`              | `notSame:key1,key2`\n[Unique](https://godoc.org/github.com/gowww/check#Unique)           | `Unique(db, \"users\", \"email\", \"?\")` | `notUnique`\n[URL](https://godoc.org/github.com/gowww/check#URL)                 | `URL`                               | `notURL`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowww%2Fcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgowww%2Fcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgowww%2Fcheck/lists"}