{"id":36579221,"url":"https://github.com/sindreslungaard/assert","last_synced_at":"2026-01-12T07:42:00.500Z","repository":{"id":57615294,"uuid":"381177364","full_name":"sindreslungaard/assert","owner":"sindreslungaard","description":"Dead simple golang validator for when you don't want to deal with struct tags ","archived":false,"fork":false,"pushed_at":"2024-05-01T14:58:18.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-20T06:38:04.346Z","etag":null,"topics":["assert","go","golang","validate","validation","validator"],"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/sindreslungaard.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}},"created_at":"2021-06-28T22:37:07.000Z","updated_at":"2024-05-01T14:49:21.000Z","dependencies_parsed_at":"2024-06-20T06:08:33.681Z","dependency_job_id":null,"html_url":"https://github.com/sindreslungaard/assert","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sindreslungaard/assert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindreslungaard%2Fassert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindreslungaard%2Fassert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindreslungaard%2Fassert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindreslungaard%2Fassert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindreslungaard","download_url":"https://codeload.github.com/sindreslungaard/assert/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindreslungaard%2Fassert/sbom","scorecard":{"id":826057,"data":{"date":"2025-08-11","repo":{"name":"github.com/sindreslungaard/assert","commit":"c07260853ef5c413066c4b0ee461fc931de72a15"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"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":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"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":"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":-1,"reason":"no workflows found","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":"Code-Review","score":0,"reason":"Found 0/22 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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"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":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"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":"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"}}]},"last_synced_at":"2025-08-23T16:40:01.491Z","repository_id":57615294,"created_at":"2025-08-23T16:40:01.492Z","updated_at":"2025-08-23T16:40:01.492Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28336663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["assert","go","golang","validate","validation","validator"],"created_at":"2026-01-12T07:42:00.439Z","updated_at":"2026-01-12T07:42:00.493Z","avatar_url":"https://github.com/sindreslungaard.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# assert \u003cimg src=\"https://storage.googleapis.com/gopherizeme.appspot.com/gophers/1dc4851c11e2ec6e05533c2e7d87df1687cf97fc.png\" alt=\"gopher\" width=\"130\" align=\"right\"\u003e\n\nDead simple 0 dependency \"typed\" golang validator\n\n### Motivation\n\nMost go validators use either struct tags or a string based representation of the validation rules, and while there's nothing wrong with that, sometimes you just want to quickly validate an input and perhaps cast it to a different type from which you received it.\n\nWith assert you may also rest assured you did not typo any of the validation rules as all rules are functions, hence a bit more \"typed\" than something like `validate:\"required,min=4,max=5\"`\n\n### Installing\n\n```\ngo get github.com/sindreslungaard/assert\n```\n\n### Examples\n\nSimple example of validating the character length of an interface and returning it as a string\n\n```go\npackage main\n\nimport \"github.com/sindreslungaard/assert\"\n\nfunc main() {\n    // This can be any value, any type.\n    src := \"some-value\"\n\n    str, err := assert.Is(src).MinLen(5).MaxLen(10).String()\n\n    if err != nil {\n        // handle error\n    }\n\n    // str == \"some-value\"\n}\n```\n\nEvery assertion formats the input to a type it prefers to test on before executing, so you can do number assertions on string values and so on\n\n```go\nnum, err := assert.Is(\"55\").MinNum(50).Int()\nnum, err := assert.Is(55).MinNum(50).Int()\n// Both of these are OK\n```\n\nExample validation for a http form POST request\n\n```go\nfunc mySignupHandler(c *gin.Context) {\n\n    username, err := assert.Is(c.PostForm(\"username\")).MinLen(3).MaxLen(20).AlphaNumeric().String()\n\n    if err != nil {\n        // let the user know\n    }\n\n    password, err := assert.Is(c.PostForm(\"password\")).MinLen(8)\n\n    if err != nil {\n        // let the user know\n    }\n\n}\n```\n\nWe can recude the number of error checks with `assert.First`\n\n```go\nfunc mySignupHandler(c *gin.Context) {\n\n    username, err1 := assert.Is(c.PostForm(\"username\")).MinLen(3).MaxLen(20).AlphaNumeric().String()\n    email,    err2 := assert.Is(c.PostForm(\"email\")).Email().String()\n    password, err3 := assert.Is(c.PostForm(\"password\")).MinLen(8).String()\n\n    err := assert.First(err1, err2, err3)\n\n    if err != nil {\n        // let the user know\n    }\n\n}\n```\n\n### Available validations\n\n| Validation   | Argument type | Description                                                                                  |\n| ------------ | ------------- | -------------------------------------------------------------------------------------------- |\n| NotEmpty     |               | Checks if the input (formatted to string) is equal to \"\"                                     |\n| MinLen       | int           | Checks if the length of input (formatted to string) is greater than or equal to the argument |\n| MaxLen       | int           | Checks if the length of input (formatted to string) is less than or equal to the argument    |\n| MinNum       | int           | Checks if the value of input (formatted to int) is greater than or equal to the argument     |\n| MaxNum       | int           | Checks if the value of input (formatted to int) is less than or equal to the argument        |\n| Regex        | string        | Checks if the input (formatted to string) matches the provided regex pattern                 |\n| Email        |               | Checks if the input (formatted to string) is a valid email                                   |\n| Alpha        |               | Checks if the input (formatted to string) only contains a-z and A-Z                          |\n| AlphaNumeric |               | Checks if the input (formatted to string) only contains a-z, A-Z and 0-9                     |\n\n### Available type cast assertions\n\nType casts should always be last in your assertion chain, they are what executes all assertions in the chain and returns any errors or the input converted to the new type.\n\n| Type    | Description                                                                                    |\n| ------- | ---------------------------------------------------------------------------------------------- |\n| String  | Formats the input as a string using `fmt.Sprintf`                                              |\n| Int     | Formats the input as an int using `fmt.Sprintf -\u003e strconv.Atoi`                                |\n| Float64 | Formats the input as a float64 using `fmt.Sprintf -\u003e strconv.ParseFloat` with 64 bit precision |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindreslungaard%2Fassert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindreslungaard%2Fassert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindreslungaard%2Fassert/lists"}