ettle / panics

Run time assertions with panics for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go Panics

Go Report Card GoDoc

import "github.com/ettle/panics"

Package panics implements some helper methods around panicing

While you should handle and return errors instead of throwing a panic (https://blog.golang.org/error-handling-and-go), there are times where having a runtime assertion is useful.

func If(condition bool, msgAndArgs ...interface{})

If will trigger a panic only if the condition is true

func IfEqual(expected, actual interface{}, msgAndArgs ...interface{})

IfEqual will trigger a panic only if the expected and actual are equal

func IfError(err error, msgAndArgs ...interface{})

IfError will trigger a panic only if the error is not nil

func IfNil(v interface{}, msgAndArgs ...interface{})

IfNil will trigger a panic only if the value is nil

func IfNot(condition bool, msgAndArgs ...interface{})

IfNot will trigger a panic only if the condition is false

func IfNotEqual(expected, actual interface{}, msgAndArgs ...interface{})

IfNotEqual will trigger a panic only if the expected and actual are not equal

func IfNotError(err error, msgAndArgs ...interface{})

IfNotError will trigger a panic only if the error is nil

func IfNotNil(v interface{}, msgAndArgs ...interface{})

IfNotNil will trigger a panic if the value is not nil

func Now(msgAndArgs ...interface{})

Now will trigger a panic

About

Run time assertions with panics for Go

License:MIT License


Languages

Language:Go 95.1%Language:Makefile 4.9%