Skip to content

alexbyk/panicif

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Copyright 2018, alexbyk.com

About

Go: panic if error shorthand

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages