{"id":13786688,"url":"https://github.com/twharmon/govalid","last_synced_at":"2026-01-31T18:16:35.804Z","repository":{"id":47721014,"uuid":"171184264","full_name":"twharmon/govalid","owner":"twharmon","description":"Struct validation using tags","archived":false,"fork":false,"pushed_at":"2025-10-24T21:56:17.000Z","size":151,"stargazers_count":109,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-24T23:26:16.231Z","etag":null,"topics":["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/twharmon.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-02-17T23:25:43.000Z","updated_at":"2025-10-24T21:56:19.000Z","dependencies_parsed_at":"2024-07-14T22:28:53.241Z","dependency_job_id":"a168467d-88be-43af-9d06-5a235fe24a74","html_url":"https://github.com/twharmon/govalid","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/twharmon/govalid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgovalid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgovalid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgovalid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgovalid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twharmon","download_url":"https://codeload.github.com/twharmon/govalid/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twharmon%2Fgovalid/sbom","scorecard":{"id":903714,"data":{"date":"2025-08-11","repo":{"name":"github.com/twharmon/govalid","commit":"a81c6fcded03208bebfda8f65d60dc2e88322f20"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.9,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/twharmon/govalid/test.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/twharmon/govalid/test.yml/main?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":1,"reason":"2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T16:36:24.255Z","repository_id":47721014,"created_at":"2025-08-24T16:36:24.255Z","updated_at":"2025-08-24T16:36:24.255Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28949280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T14:26:55.697Z","status":"ssl_error","status_checked_at":"2026-01-31T14:26:52.545Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["go","validation"],"created_at":"2024-08-03T19:01:28.532Z","updated_at":"2026-01-31T18:16:35.799Z","avatar_url":"https://github.com/twharmon.png","language":"Go","funding_links":[],"categories":["Utility","Validation","校验库","验证","校验库`用于校验的库`"],"sub_categories":["Utility/Miscellaneous","查询语","HTTP Clients","实用程序/Miscellaneous","Fail injection"],"readme":"# Govalid\n\n[![](https://goreportcard.com/badge/github.com/twharmon/govalid)](https://goreportcard.com/report/github.com/twharmon/govalid)\n\nUse Govalid to validate structs.\n\n## Basic Example\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"log\"\n\t\"strings\"\n\t\"unicode/utf8\"\n\n\t\"github.com/twharmon/govalid\"\n)\n\ntype Post struct {\n\t// ID has no constraints\n\tID int\n\n\t// Title is required, must be at least 3 characters long, and\n\t// cannot be more than 20 characters long\n\tTitle string `valid:\"req|min:3|max:20\"`\n\n\t// Body is not required, cannot be more than 10000 charachers,\n\t// and must be \"fun\" (a custom rule defined below).\n\tBody string `valid:\"max:10000|fun\"`\n}\n\nfunc main() {\n\t// Add custom string rule \"fun\" that can be used on any string field\n\t// in any struct.\n\tgovalid.Rule(\"fun\", func(v any) error {\n\t\tswitch tv := v.(type) {\n\t\tcase string:\n\t\t\tif float64(strings.Count(tv, \"!\"))/float64(utf8.RuneCountInString(tv)) \u003e 0.001 {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\t// return a validation error with govalid.Error\n\t\t\treturn govalid.NewValidationError(\"must contain more exclamation marks\")\n\t\tdefault:\n\t\t\t// return a non validation (internal) error\n\t\t\treturn errors.New(\"fun constraint must be applied to string only\")\n\t\t}\n\t})\n\tfmt.Println(govalid.Validate(\u0026Post{\n\t\tID:    5,\n\t\tTitle: \"Hi\",\n\t\tBody:  \"Hello world!\",\n\t}))\n}\n```\n\n## Error Values\nWhen you call `govalid.Validate` to validate a struct, it returns an error if the validation rules are not met. This error may either be a validation-specific error (an implementation of `govalid.ValidationError`) or a different error indicating a problem in processing the validation. This allows you to distinguish between errors caused by invalid data and those caused by issues in your validation logic, such as setting the `valid` tag to `max:not-a-number`.\n\n```go\nif err := govalid.Validate(value); err != nil {\n\tif verr, ok := err.(govalid.ValidationError); ok {\n\t\tfmt.Println(\"validation error\", verr)\n\t} else {\n\t\tfmt.Println(\"some other error\", err)\n\t}\n}\n```\n\n## Dive Usage\nThe `dive` rule is used to apply validation rules to elements within pointers, slices, arrays, and structs. When the `dive` rule is encountered, it instructs the validator to \"dive\" into the elements of the collection or the value pointed to by a pointer and apply the remaining rules to each element or the dereferenced value.\n\n### Notes\n- **Pointers**: The `dive` rule will dereference the pointer and apply the remaining rules to the value it points to.\n- **Slices/Arrays**: The `dive` rule will iterate over each element in the slice or array and apply the remaining rules to each element.\n- **Structs**: The `dive` rule will validate the struct according to its own field tags. The remaining rules after `dive` have no meaning for structs.\n\n### Examples\n\n#### Pointers\n\n```go\ntype Example struct {\n    Field *string `valid:\"req|dive|min:3\"`\n}\n```\nIn this example, the Field must be a non-nil pointer to a string, and the string must be at least 3 characters long.\n\n#### Slices/Arrays\n```go\ntype Example struct {\n    Field []string `valid:\"req|dive|min:3\"`\n}\n```\nIn this example, the Field must be a non-nil slice of strings, and each string in the slice must be at least 3 characters long.\n\n#### Structs\n```go\ntype Inner struct {\n    Name string `valid:\"req\"`\n}\n\ntype Outer struct {\n    InnerStruct Inner `valid:\"dive\"`\n}\n```\nIn this example, the InnerStruct field will be validated according to the validation tags defined in the Inner struct.\n\n\n## Contribute\n\nMake a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fgovalid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwharmon%2Fgovalid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwharmon%2Fgovalid/lists"}