{"id":13670146,"url":"https://github.com/timakin/bodyclose","last_synced_at":"2025-05-14T01:10:32.373Z","repository":{"id":43126580,"uuid":"177233187","full_name":"timakin/bodyclose","owner":"timakin","description":"Analyzer: checks whether HTTP response body is closed and a re-use of TCP connection is not blocked.","archived":false,"fork":false,"pushed_at":"2024-12-22T09:18:01.000Z","size":92,"stargazers_count":315,"open_issues_count":24,"forks_count":34,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-03T14:19:16.201Z","etag":null,"topics":["code-analysis","go","golang","http","linter","linter-plugin","request","static-analysis"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timakin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-23T02:09:48.000Z","updated_at":"2025-03-08T09:05:14.000Z","dependencies_parsed_at":"2023-01-21T12:29:20.726Z","dependency_job_id":"90d50849-8f04-4123-bcc2-3e3e198b5b52","html_url":"https://github.com/timakin/bodyclose","commit_stats":{"total_commits":76,"total_committers":15,"mean_commits":5.066666666666666,"dds":0.3157894736842105,"last_synced_commit":"adbc21e6bf369ca6d936dbb140733f34867639bd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fbodyclose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fbodyclose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fbodyclose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fbodyclose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timakin","download_url":"https://codeload.github.com/timakin/bodyclose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248272002,"owners_count":21075809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-analysis","go","golang","http","linter","linter-plugin","request","static-analysis"],"created_at":"2024-08-02T09:00:33.782Z","updated_at":"2025-04-10T18:47:21.624Z","avatar_url":"https://github.com/timakin.png","language":"Go","readme":"# bodyclose\n\n[![CircleCI](https://circleci.com/gh/timakin/bodyclose.svg?style=svg)](https://circleci.com/gh/timakin/bodyclose)\n\n`bodyclose` is a static analysis tool which checks whether `res.Body` is correctly closed.\n\n## Install\n\nYou can get `bodyclose` by `go get` command.\n\n```bash\n$ go get -u github.com/timakin/bodyclose\n```\n\n## How to use\n\n`bodyclose` run with `go vet` as below when Go is 1.12 and higher.\n\n```bash\n$ go vet -vettool=$(which bodyclose) github.com/timakin/go_api/...\n# github.com/timakin/go_api\ninternal/httpclient/httpclient.go:13:13: response body must be closed\n```\n\nWhen Go is lower than 1.12, just run `bodyclose` command with the package name (import path).\n\nBut it cannot accept some options such as `--tags`.\n\n```bash\n$ bodyclose github.com/timakin/go_api/...\n~/go/src/github.com/timakin/api/internal/httpclient/httpclient.go:13:13: response body must be closed\n```\n\n## Analyzer\n\n`bodyclose` validates whether [*net/http.Response](https://golang.org/pkg/net/http/#Response) of HTTP request calls method `Body.Close()` such as below code.\n\n```go\nresp, err := http.Get(\"http://example.com/\") // Wrong case\nif err != nil {\n\t// handle error\n}\nbody, err := ioutil.ReadAll(resp.Body)\n```\n\nThis code is wrong. You must call resp.Body.Close when finished reading resp.Body.\n\n```go\nresp, err := http.Get(\"http://example.com/\")\nif err != nil {\n\t// handle error\n}\ndefer resp.Body.Close() // OK\nbody, err := ioutil.ReadAll(resp.Body)\n```\n\nIn the [GoDoc of Client.Do](https://golang.org/pkg/net/http/#Client.Do) this rule is clearly described.\n\nIf you forget this sentence, a HTTP client cannot re-use a persistent TCP connection to the server for a subsequent \"keep-alive\" request.\n","funding_links":[],"categories":["Linters","Programming Languages","Go"],"sub_categories":["Bugs"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fbodyclose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimakin%2Fbodyclose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fbodyclose/lists"}