Documentation
¶
Overview ¶
Package funchelpers provides small helpers related to writing easy-to-understand Go functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func VerifyClose ¶
VerifyClose is shorthand for `VerifyError(Err, closer.Close)`.
func VerifyError ¶
VerifyError is a helper designed to make verifying deferred functions that return errors more ergonomic (most notably Close). This helper is intended to be used with named return values.
func foo() (Err error) {
f, err := os.Create("foobar")
if err != nil {
return err
}
defer funchelpers.VerifyError(&Err, foo.Close)
return nil
}
which is equivalent to
func foo() (Err error) {
f, err := os.Create("foobar")
if err != nil {
return err
}
defer func() {
if err := f.Close(); err != nil && Err == nil {
Err = err
}
}
return nil
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.