funchelpers

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

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

func VerifyClose(Err *error, closer io.Closer)

VerifyClose is shorthand for `VerifyError(Err, closer.Close)`.

func VerifyError

func VerifyError(Err *error, closeFn func() error)

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.

Jump to

Keyboard shortcuts

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