{"id":13837046,"url":"https://github.com/storozhukBM/verifier","last_synced_at":"2025-07-10T16:31:51.878Z","repository":{"id":57498892,"uuid":"141836017","full_name":"storozhukBM/verifier","owner":"storozhukBM","description":"Package verifier provides simple defensive programing primitives.","archived":false,"fork":false,"pushed_at":"2020-02-02T21:24:19.000Z","size":38,"stargazers_count":268,"open_issues_count":1,"forks_count":7,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-05T15:05:36.726Z","etag":null,"topics":["defensive-programing","error-handling","golang","verification"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/storozhukBM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-21T18:15:29.000Z","updated_at":"2024-04-17T09:10:32.000Z","dependencies_parsed_at":"2022-09-06T17:11:37.193Z","dependency_job_id":null,"html_url":"https://github.com/storozhukBM/verifier","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/storozhukBM%2Fverifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storozhukBM%2Fverifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storozhukBM%2Fverifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storozhukBM%2Fverifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/storozhukBM","download_url":"https://codeload.github.com/storozhukBM/verifier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225648200,"owners_count":17502173,"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":["defensive-programing","error-handling","golang","verification"],"created_at":"2024-08-04T15:00:59.889Z","updated_at":"2024-11-20T23:32:12.844Z","avatar_url":"https://github.com/storozhukBM.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# Verifier \"Defend against the impossible, because the impossible will happen.\" [![Build Status](https://travis-ci.org/storozhukBM/verifier.svg?branch=master)](https://travis-ci.org/storozhukBM/verifier)  [![Go Report Card](https://goreportcard.com/badge/github.com/storozhukBM/verifier)](https://goreportcard.com/report/github.com/storozhukBM/verifier) [![Coverage Status](https://coveralls.io/repos/github/storozhukBM/verifier/badge.svg?branch=master)](https://coveralls.io/github/storozhukBM/verifier?branch=master\u0026k=1) [![GoDoc](https://godoc.org/github.com/storozhukBM/verifier?status.svg)](http://godoc.org/github.com/storozhukBM/verifier)\n\nPackage `verifier` provides simple [defensive programing](https://en.wikipedia.org/wiki/Defensive_programming) primitives.\n\nSome software has higher than usual requirements for availability, safety or security.\nOften in such projects people practice pragmatic paranoia with specific set of rules.\nFor example: each public function on any level of your application should check all arguments passed to it. Obviously checking for nil pointers, but also states and conditions, that it will rely on.\n\nWhen you use such approaches your code can become a mess. And sometimes it's hard to distinguish between verification code and underlying business logic.\n\nThis small library is built on error handling pattern described by Rob Pike in Go blog called \n[Errors are values](https://blog.golang.org/errors-are-values).\n\nIt helps you quickly transform code from this\n```go\nif transfer == nil {\n\treturn nil, errors.New(\"transfer can't be nil\")\n}\nif person == nil {\n\treturn nil, errors.New(\"person can't be nil\")\n}\nif transfer.Destination == \"\" {\n\treturn nil, errors.New(\"transfer destination can't be empty\")\n}\nif transfer.Amount \u003c= 0 {\n\treturn nil, errors.New(\"transfer amount should be greater than zero\")\n}\nif person.Name == \"\" {\n\treturn nil, errors.New(\"name can't be empty\")\n}\nif person.Age \u003c 21 {\n\treturn nil, fmt.Errorf(\"age should be 21 or higher, but yours: %d\", person.Age)\n}\nif !person.HasLicense {\n\treturn nil, errors.New(\"customer should have license\")\n}\n```\nto this\n```go\nverify := verifier.New()\nverify.That(transfer != nil, \"transfer can't be nil\")\nverify.That(person != nil, \"person can't be nil\")\nif verify.GetError() != nil {\n\treturn nil, verify.GetError()\n}\nverify.That(transfer.Destination != \"\", \"transfer destination can't be empty\")\nverify.That(transfer.Amount \u003e 0, \"transfer amount should be greater than zero\")\nverify.That(person.Name != \"\", \"name can't be empty\")\nverify.That(person.Age \u003e= 21, \"age should be 21 or higher, but yours: %d\", person.Age)\nverify.That(person.HasLicense, \"customer should have license\")\nif verify.GetError() != nil {\n\treturn nil, verify.GetError()\n}\n```\n\nIt also can help you to track down unchecked verifiers when you forget to do it \n```go\nverify := verifier.New()\nverify.That(user.HasPermission(READ, ACCOUNTS), \"user has no permission to read accounts\")\n```\n\nIn this example we have forgot to check verifier using verify.GetError() and\nafter some time you'll see in your log such error:\n```\n[ERROR] found unhandled verification: verification failure: user has no permission to read accounts\n  verification was created here:\n  github.com/storozhukBM/verifier_test.TestVerifier\n    /Users/bogdanstorozhuk/verification-lib/src/github.com/storozhukBM/verifier/verifier_test.go:91\n  testing.tRunner\n    /usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:777\n  runtime.goexit\n    /usr/local/Cellar/go/1.10.2/libexec/src/runtime/asm_amd64.s:2361\n```\n\nIf you don't want/need such tracking use zero verifier `verifier.Verify{}`.\nYou can also redirect output from this package using `verifier.SetUnhandledVerificationsWriter(io.Writer)` method.\n\n---\n##### There is other libraries that can be useful when you employ defensive programming style\n* [vala](https://github.com/kat-co/vala)\n* [govalidate](https://github.com/tonyhb/govalidate)\n\n---\n##### License\nCopyright 2018 Bohdan Storozhuk\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FstorozhukBM%2Fverifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FstorozhukBM%2Fverifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FstorozhukBM%2Fverifier/lists"}