{"id":17722802,"url":"https://github.com/bramp/govalidator","last_synced_at":"2025-03-31T13:25:19.930Z","repository":{"id":24899333,"uuid":"28315826","full_name":"bramp/govalidator","owner":"bramp","description":"Golang input validator","archived":false,"fork":false,"pushed_at":"2014-12-23T06:34:32.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T18:51:08.678Z","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":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bramp.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":"2014-12-21T22:38:32.000Z","updated_at":"2014-12-23T06:34:33.000Z","dependencies_parsed_at":"2022-08-23T09:50:56.464Z","dependency_job_id":null,"html_url":"https://github.com/bramp/govalidator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Fgovalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Fgovalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Fgovalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Fgovalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bramp","download_url":"https://codeload.github.com/bramp/govalidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246473273,"owners_count":20783236,"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-10-25T15:39:25.033Z","updated_at":"2025-03-31T13:25:19.894Z","avatar_url":"https://github.com/bramp.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"govalidator\n============\n2014 by [Andrew Brampton](http://bramp.net)\n\nSimple input validation for Google Go / Golang. Use the below examples, or read the [godocs](https://godoc.org/github.com/bramp/govalidator).\n\nInstall\n-------\n```bash\n$ go get github.com/bramp/govalidator\n```\n\n```go\nimport (\n    \"github.com/bramp/govalidator\"\n)\n```\n\nString Example\n-------\n```go\nvalidator := NewStringValidator().TrimSpace().NotEmpty()\ns, errs := validator.Validate(\" blah \")\n// s == \"blah\" and errs == nil\n\ns, errs := validator.Validate(\"  \")\n// s == \"\" and errs = {ErrEmpty}\n```\n\nString to Integer Example\n-------\n```go\nvalidator := NewStringValidator().AsInt().Range(0, 10)\ni, errs := validator.Validate(\"10\")\n// i == 10, and errs == nil\n\ni, errs := validator.Validate(\"foo\")\n// errs = {ErrNotAInteger}\n\ni, errs := validator.Validate(\"1000\")\n// errs = {ErrTooLarge}\n```\n\nMap Example\n-------\n```go\n// Create a map validator, that expects only two fields\nvalidator := NewMapValidator().\n    FailOnUnknown().\n    Key(\"field\").NotEmpty().\n    Key(\"number\").AsInt().Range(1, 10)\n\nm := map[string]interface{}{\n    \"field\":  \"value\",\n    \"number\": \"10\",\n}\n\nm, errs := validator.Validate(m)\n// Returns {\n//   \"field\" : \"value\",\n//   \"number\": 10,      // Note: int not string.\n// }\n// and errs == nil\nif len(errs) != 0 || len(m) != 2 || m[\"field\"] != \"value\" || m[\"number\"] != 10 {\n    t.Errorf(\"Failed map test %v %v\", m, errs)\n}\n\n// However\nm = map[string]interface{}{\n    \"field\":  \"\",\n    \"number\": \"1000\",\n    \"other\":  \"value\",\n}\nm, errs = validator.Validate(m)\n// Returns {\n//   \"field\" : \"\",\n//   \"number\": 1000,\n// }\n// and errs == {ErrEmpty, ErrTooLarge, ErrUnknownKey}\nif len(errs) != 3 || len(m) != 2 || m[\"field\"] != \"\" || m[\"number\"] != 1000 {\n    t.Errorf(\"Failed map test %v %v\", m, errs)\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramp%2Fgovalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbramp%2Fgovalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramp%2Fgovalidator/lists"}