Skip to content
/ panics Public

Run time assertions with panics for Go

License

Notifications You must be signed in to change notification settings

ettle/panics

Repository files navigation

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