Help us shape the future of Go! Take the 2026 Go Developer Survey

closer

package module
v0.1.1-0...-c0ea28e Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2020 License: Unlicense Imports: 2 Imported by: 1

README

Closer

Go library providing utilities to handle io.Closer in defer statements.

Install

go get github.com/normegil/closer

Documentation

See godoc for documentation.

You can compose your own struct with CloseErrorHandlerRequired or use directly the CloseErrorHandler interface.

Available handlers:

Documentation

Overview

Closer will help you manage errors in io.Closer used in defer consistently

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloseErrorHandler

type CloseErrorHandler interface {
	Close(c io.Closer)
}

CloseErrorHandler defines the interface to use to handle io.Closer errors

type CloseErrorHandlerRequired

type CloseErrorHandlerRequired struct {
	Handler CloseErrorHandler
}

CloseErrorHandlerRequired can be used to compose your own struct to use a CloseErrorHandler, or fallback on DiscardErrorHandler if required

func (CloseErrorHandlerRequired) CloseHandler

CloseHandler will return your io.Closer handler, or a DiscardErrorHandler if no handler was defined

type DiscardErrorHandler

type DiscardErrorHandler struct {
}

DiscardErrorHandler will discard errors returned by io.Closer if any

func (DiscardErrorHandler) Close

func (r DiscardErrorHandler) Close(c io.Closer)

Close will discard errors returned by io.Closer if any

type FuncErrorHandler

type FuncErrorHandler struct {
	// contains filtered or unexported fields
}

FuncErrorHandler register a function to call when closing an io.Closer

func CloseErrorHandlerFunc

func CloseErrorHandlerFunc(fn func(closer io.Closer)) *FuncErrorHandler

CloseErrorHandlerFunc is a convenience method to create a FuncErrorHandler

func (FuncErrorHandler) Close

func (f FuncErrorHandler) Close(closer io.Closer)

Close call the registered function with the passed io.Closer

type LogErrorHandler

type LogErrorHandler struct {
	// Fatal should be set to true if the logging should happen on fatal level
	Fatal bool
}

LogErrorHandler will log errors returned by io.Closer

func (LogErrorHandler) Close

func (r LogErrorHandler) Close(c io.Closer)

Close will log errors returned by io.Closer

type PanicErrorHandler

type PanicErrorHandler struct {
}

PanicErrorHandler will panic on errors returned by io.Closer if any

func (PanicErrorHandler) Close

func (r PanicErrorHandler) Close(c io.Closer)

Close will panic on errors returned by io.Closer if any

Jump to

Keyboard shortcuts

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