https://github.com/tty2/deferred
tiny lib that provides helpers to write deferred calls with one line
https://github.com/tty2/deferred
Last synced: 8 months ago
JSON representation
tiny lib that provides helpers to write deferred calls with one line
- Host: GitHub
- URL: https://github.com/tty2/deferred
- Owner: tty2
- License: mit
- Created: 2022-07-21T12:32:03.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-07-21T15:03:47.000Z (almost 4 years ago)
- Last Synced: 2025-10-12T13:23:40.994Z (8 months ago)
- Language: Go
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
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:
```go
...
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)