A static analysis tool for Go that checks whether HTTP response bodies are properly closed to enable TCP connection reuse.
bodyclose is a static analysis tool for Go that checks whether HTTP response bodies are properly closed in code. It solves the problem of resource leaks and blocked TCP connection reuse that occurs when developers forget to call `resp.Body.Close()` after making HTTP requests.
Go developers building HTTP clients or services that make external API calls, particularly those concerned with performance and resource management.
Developers choose bodyclose because it integrates seamlessly with Go's standard tooling (`go vet`), automatically enforces a critical best practice, and helps prevent subtle bugs that affect application performance and stability.
Analyzer: checks whether HTTP response body is closed and a re-use of TCP connection is not blocked.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Seamlessly plugs into the standard `go vet` tool, making adoption straightforward for Go developers familiar with the ecosystem.
The `-check-consumption` flag adds an extra layer of validation by ensuring response bodies are read before closing, catching more subtle bugs.
Recognizes common consumption patterns like `io.ReadAll` and `json.NewDecoder`, reducing false positives for standard use cases.
Offers a standalone CLI for Go versions below 1.12, ensuring compatibility with older codebases.
Fails to detect non-standard consumption logic, requiring developers to manually suppress warnings with `//nolint:bodyclose` comments, as admitted in the README.
Does not check if `Close()` is called before consumption, missing a class of runtime errors that could occur, which is a noted limitation.
Relies on `go vet` for integration, which might not be ideal for all development setups or continuous integration pipelines without additional configuration.