internal

package
v0.0.0-...-78c255e Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseIO

func CloseIO(c io.Closer, contextString string)

CloseIO is a little helper to close an io.Closer and log any error encountered.

Based off of https://blevesearch.com/news/Deferred-Cleanup,-Checking-Errors,-and-Potential-Problems/

Probably, most relevant for closing HTTP response bodies as they MUST be closed, even if you don’t read it. https://manishrjain.com/must-close-golang-http-response

Usage: ```go res, err := client.Do(req) defer internal.CloseIO(res.Body, "request body") ```

Alternative to this bulky pattern:

```go res, err := client.Do(req)

defer func(c io.Closer) {
	if c != nil {
		err := c.Close()
		if err != nil {
			log.Fatalf("error closing request body stream %v", err)
		}
	}
}(res.Body)

```

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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