Instead of writing
err := IsPositive(-1)
if err != nil {
panic(err)
}
use a shorthand:
panicif.Err(IsPositive(-1))
go get -u github.com/alexbyk/panicif
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