Documentation
¶
Overview ¶
The main use case for runutil package is when you want to close a `Closer` interface. As we all know, we should close all implements of `Closer`, such as *os.File. Commonly we will use:
defer closer.Close()
The problem is that Close() usually can return important error e.g for os.File the actual file flush might happen (and fail) on `Close` method. It's important to *always* check error. Thanos provides utility functions to log every error like those, allowing to put them in convenient `defer`:
defer runutil.CloseWithLogOnErr(logger, closer, "log format message")
For capturing error, use CloseWithErrCapture:
var err error defer runutil.CloseWithErrCapture(&err, closer, "log format message") // ...
If Close() returns error, err will capture it and return by argument.
The rununtil.Exhaust* family of functions provide the same functionality but they take an io.ReadCloser and they exhaust the whole reader before closing them. They are useful when trying to use http keep-alive connections because for the same connection to be re-used the whole response body needs to be exhausted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseWithLogOnErr ¶
CloseWithLogOnErr is making sure we log every error, even those from best effort tiny closers.
func ExhaustCloseRequestBodyHandler ¶
ExhaustCloseRequestBodyHandler ensures that request body is well closed and exhausted at the end of server call.
func ExhaustCloseWithLogOnErr ¶
func ExhaustCloseWithLogOnErr(logger log.Logger, r io.ReadCloser, format string)
ExhaustCloseWithLogOnErr closes the io.ReadCloser with a log message on error but exhausts the reader before.
Types ¶
This section is empty.