Skip to content

tty2/deferred

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

deferred

idea:

This is a tiny library that contains helpers to close any closer that returns error with defer.

The general idea is simple: make it with one line.

example:

    ...
    resp, err := http.Get("http://example.com/")
    if err != nil {
        // Handle error
    }

    defer deferred.CloseOrLog(resp.Body, logger)
    ...

list of methods:

// pass logger you use in your code
- CloseOrLog(cl io.Closer, log logger)  
- CloseOrLogCtx(ctx context.Context, cl io.Closer, log logger)

// only if you don't mind using standard log
- CloseOrLogStd(cl io.Closer)              
- CloseOrLogStdCtx(ctx context.Context, cl io.Closer)

About

tiny lib that provides helpers to write deferred calls with one line

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages