• Stars
    star
    303
  • Rank 136,862 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Analyzer: checks whether HTTP response body is closed and a re-use of TCP connection is not blocked.

bodyclose

CircleCI

bodyclose is a static analysis tool which checks whether res.Body is correctly closed.

Install

You can get bodyclose by go get command.

$ go get -u github.com/timakin/bodyclose

How to use

bodyclose run with go vet as below when Go is 1.12 and higher.

$ go vet -vettool=$(which bodyclose) github.com/timakin/go_api/...
# github.com/timakin/go_api
internal/httpclient/httpclient.go:13:13: response body must be closed

When Go is lower than 1.12, just run bodyclose command with the package name (import path).

But it cannot accept some options such as --tags.

$ bodyclose github.com/timakin/go_api/...
~/go/src/github.com/timakin/api/internal/httpclient/httpclient.go:13:13: response body must be closed

Analyzer

bodyclose validates whether *net/http.Response of HTTP request calls method Body.Close() such as below code.

resp, err := http.Get("http://example.com/") // Wrong case
if err != nil {
	// handle error
}
body, err := ioutil.ReadAll(resp.Body)

This code is wrong. You must call resp.Body.Close when finished reading resp.Body.

resp, err := http.Get("http://example.com/")
if err != nil {
	// handle error
}
defer resp.Body.Close() // OK
body, err := ioutil.ReadAll(resp.Body)

In the GoDoc of Client.Do this rule is clearly described.

If you forget this sentence, a HTTP client cannot re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

More Repositories

1

gopli

DB replication tool to synchronize data with multi environments written in Golang.
Go
344
star
2

md2mid

CLI tool to publish your medium articles with markdown
Go
35
star
3

gonvert

Golang character encoding converter with an automatic code-estimation.
Go
26
star
4

qunosy

Personal Gunosy for Qiita
Python
18
star
5

autocompl

A light-weight autocomplete integration for Rails application.
Ruby
17
star
6

gosto

Google Cloud Datastore Client Wrapper in Go, for automation of key attachment.
Go
14
star
7

jf

Dead simple JSON Formatter
Ruby
10
star
8

ganbaruzoi

すごいがんばるためのアレ
JavaScript
10
star
9

octop

Command line tool to easily catch up streams of notifications for your Github events.
Go
10
star
10

ts

TechStack: Subscribe tech headlines from terminal.
Go
9
star
11

respmask

Go middleware for dynamically masking specific fields in JSON responses
Go
9
star
12

ssm2env

Environments injection tool for AWS EC2, with SSM (EC2 Parameter Store).
Go
7
star
13

deeeetify

#deeeet風 Image generator
Go
6
star
14

dsmock

dsmock is a fixture-injector for appengine datastore, based on YAML format fixtures
Go
6
star
15

airshooter

High-performance Notification and Messaging API for asynchronous job.
Go
6
star
16

capistrano3-ridgepole

Capistrano3 plugin for ridgepole tasks
Ruby
4
star
17

reviewdog-orb

CircleCI Orbs for reviewdog
Shell
3
star
18

codemagnet_app

JavaScript
3
star
19

json_schema_power_validator

Test JSON Schema itself
Ruby
2
star
20

miyuki

Miyuki bot on GKE
Go
2
star
21

dotfiles

VimやZshの設定ファイル
Vim Script
2
star
22

timabank

ちまぎん
2
star
23

itamae-plugin-resource-npm

Itamae plugin to manipulate node packages.
Ruby
1
star
24

circleci-orbs

The yaml sources for the CircleCI orbs.
Makefile
1
star
25

syncia

Filesync like Dropbox with Ruby code.
Ruby
1
star
26

menhera

お前はメンヘラ
Ruby
1
star
27

ansible-perl

Ansible role for perl installation. It's able to flexibly specify the version.
1
star
28

pppb

[WIP] Pretty Printer for Protocol Buffer
Go
1
star
29

algome

computer science learning with JavaScript and C++
C++
1
star
30

Academic_Report_and_R_resources

Academic report analysis with R or Stata, and pdf file of undergraduate final report.
R
1
star
31

dratini

Spot push notification server in Go
Go
1
star