panicif

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2019 License: MIT Imports: 2 Imported by: 4

README

Build Status

About

Instead of writing

err := IsPositive(-1)
if err != nil {
  panic(err)
}

use a shorthand:

panicif.Err(IsPositive(-1))

Installation

go get -u github.com/alexbyk/panicif

Usage

package main

import (
  "fmt"

  "github.com/alexbyk/panicif"
)

func IsPositive(val int) error {
  if val < 0 {
    return fmt.Errorf("%d isn't a positive integer", val)
  }
  return nil
}

// will panic
func main() {
  panicif.Err(IsPositive(-1))
}

Copyright 2018, alexbyk.com

Documentation

Overview

Package panicif provides shorthands for error handling. Instead of:

if err != nil {
  panic(err)
}

you can write:

panicif.Err(err)

Be aware that an invocation to Err may not be inlined (last time I checked it's not), so don't use it for a critical piece of code

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(err error)

Err panics with a given argument if the argument isn't nil

func False added in v1.0.2

func False(cond bool, format string, a ...interface{})

False panics if the first argument is true

func Nil added in v1.1.0

func Nil(val interface{}, format string, a ...interface{})

Nil panics if the first argument is a nil interface, pointer, map, array, slice, chan or funcion

func NotNil added in v1.1.0

func NotNil(val interface{}, format string, a ...interface{})

NotNil panics if the first argument isn't a nil interface, pointer, map, array, slice, chan or funcion

func True added in v1.0.1

func True(cond bool, format string, a ...interface{})

True panics if the first argument is true

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL