All Projects → storozhukBM → Verifier

storozhukBM / Verifier

Licence: apache-2.0
Package verifier provides simple defensive programing primitives.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Verifier

react-native-sms-user-consent
React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort.
Stars: ✭ 45 (-82.95%)
Mutual labels:  verification
rust-error-handle
detail rust error handle
Stars: ✭ 47 (-82.2%)
Mutual labels:  error-handling
go-errors
Flexible, general-purpose error handling for Go.
Stars: ✭ 17 (-93.56%)
Mutual labels:  error-handling
groot
Static verification tool for DNS zone files
Stars: ✭ 60 (-77.27%)
Mutual labels:  verification
NeverBounceAPI-PHP
This package provides convenient methods to integrate the NeverBounce API into your project.
Stars: ✭ 22 (-91.67%)
Mutual labels:  verification
go-mtree
File systems verification utility and library, in likeness of mtree(8)
Stars: ✭ 55 (-79.17%)
Mutual labels:  verification
Rel
Binsec/Rel is an extension of Binsec that implements relational symbolic execution for constant-time verification and secret-erasure at binary-level.
Stars: ✭ 27 (-89.77%)
Mutual labels:  verification
bugsnag-wordpress
Bugsnag error monitoring for WordPress sites
Stars: ✭ 20 (-92.42%)
Mutual labels:  error-handling
errors
Simple error handling primitives that work well with structured logging
Stars: ✭ 28 (-89.39%)
Mutual labels:  error-handling
domain-browser
Node's domain module for the web browser
Stars: ✭ 30 (-88.64%)
Mutual labels:  error-handling
silver
Definition of the Viper intermediate verification language.
Stars: ✭ 28 (-89.39%)
Mutual labels:  verification
ErrorHandler
This is a library for Google Apps Script projects. It provides methods to perform an Exponential backoff logic whenever it is needed and rewrite error objects before sending them to Stackdriver Logging.
Stars: ✭ 14 (-94.7%)
Mutual labels:  error-handling
awesome-dv
Awesome ASIC design verification
Stars: ✭ 76 (-71.21%)
Mutual labels:  verification
jsonerror
Makes Go error-handling a breeze!
Stars: ✭ 28 (-89.39%)
Mutual labels:  error-handling
result
A lightweight C++11-compatible error-handling mechanism
Stars: ✭ 121 (-54.17%)
Mutual labels:  error-handling
DLV
Safety Verification of Deep Neural Networks
Stars: ✭ 45 (-82.95%)
Mutual labels:  verification
validator
💯Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
Stars: ✭ 9,721 (+3582.2%)
Mutual labels:  error-handling
chain
Extensible, Type Safe Error Handling in Haskell
Stars: ✭ 13 (-95.08%)
Mutual labels:  error-handling
errz
Error Handling In One Line
Stars: ✭ 34 (-87.12%)
Mutual labels:  error-handling
vercors
The VerCors verification toolset for verifying parallel and concurrent software
Stars: ✭ 30 (-88.64%)
Mutual labels:  verification

Verifier "Defend against the impossible, because the impossible will happen." Build Status Go Report Card Coverage Status GoDoc

Package verifier provides simple defensive programing primitives.

Some software has higher than usual requirements for availability, safety or security. Often in such projects people practice pragmatic paranoia with specific set of rules. For 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.

When you use such approaches your code can become a mess. And sometimes it's hard to distinguish between verification code and underlying business logic.

This small library is built on error handling pattern described by Rob Pike in Go blog called Errors are values.

It helps you quickly transform code from this

if transfer == nil {
	return nil, errors.New("transfer can't be nil")
}
if person == nil {
	return nil, errors.New("person can't be nil")
}
if transfer.Destination == "" {
	return nil, errors.New("transfer destination can't be empty")
}
if transfer.Amount <= 0 {
	return nil, errors.New("transfer amount should be greater than zero")
}
if person.Name == "" {
	return nil, errors.New("name can't be empty")
}
if person.Age < 21 {
	return nil, fmt.Errorf("age should be 21 or higher, but yours: %d", person.Age)
}
if !person.HasLicense {
	return nil, errors.New("customer should have license")
}

to this

verify := verifier.New()
verify.That(transfer != nil, "transfer can't be nil")
verify.That(person != nil, "person can't be nil")
if verify.GetError() != nil {
	return nil, verify.GetError()
}
verify.That(transfer.Destination != "", "transfer destination can't be empty")
verify.That(transfer.Amount > 0, "transfer amount should be greater than zero")
verify.That(person.Name != "", "name can't be empty")
verify.That(person.Age >= 21, "age should be 21 or higher, but yours: %d", person.Age)
verify.That(person.HasLicense, "customer should have license")
if verify.GetError() != nil {
	return nil, verify.GetError()
}

It also can help you to track down unchecked verifiers when you forget to do it

verify := verifier.New()
verify.That(user.HasPermission(READ, ACCOUNTS), "user has no permission to read accounts")

In this example we have forgot to check verifier using verify.GetError() and after some time you'll see in your log such error:

[ERROR] found unhandled verification: verification failure: user has no permission to read accounts
  verification was created here:
  github.com/storozhukBM/verifier_test.TestVerifier
    /Users/bogdanstorozhuk/verification-lib/src/github.com/storozhukBM/verifier/verifier_test.go:91
  testing.tRunner
    /usr/local/Cellar/go/1.10.2/libexec/src/testing/testing.go:777
  runtime.goexit
    /usr/local/Cellar/go/1.10.2/libexec/src/runtime/asm_amd64.s:2361

If you don't want/need such tracking use zero verifier verifier.Verify{}. You can also redirect output from this package using verifier.SetUnhandledVerificationsWriter(io.Writer) method.


There is other libraries that can be useful when you employ defensive programming style

License

Copyright 2018 Bohdan Storozhuk

Licensed 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

http://www.apache.org/licenses/LICENSE-2.0

Unless 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].