Import symbol ! to passthrough errors
! is abbreviation of not nil
For example, to call function Sub in caller
func Sub(...) (T1, T2, error) {...}
func caller(...) (T3, error) {
// call Sub(...)
}
a, b, err := Sub(...)
if err != nil {
// do something
}
a, b, ! := Sub(...)
// Equivalent to
a, b, err := Sub()
if err != nil {
return (default value of T3), err
}
a, b, !checkError := Sub(...)
// Equivalent to
a, b, err := Sub()
! = checkError(err)
!checkT1, b, !checkError := Sub(...)
// Equivalent to
a, b, err := Sub()
! = checkError(err)
! = checkT1(a)
Check funcs:
// prototype
func CheckReturn(r interface{}) error {...}
func checkError(err error) error {
if err != nil {
return errors.Wrap(err, "additional message")
}
return nil
}
func checkT1(a T1) error {
if a.EqualTo(...) {
return errors.Errorf("....")
}
return nil
}
For whatever it's worth, I really like this one!