Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.5k
feat: add reuseconn linter#3464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -187,3 +187,5 @@ require ( | ||
| gopkg.in/yaml.v2 v2.4.0 // indirect | ||
| mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect | ||
| ) | ||
| require github.com/atzoum/reuseconn v0.1.0 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Should this be moved up into the existing block of indirect required modules? | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package golinters | ||
| import ( | ||
| "github.com/atzoum/reuseconn/reuseconn" | ||
| "golang.org/x/tools/go/analysis" | ||
| "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
| ) | ||
| func NewReuseconn() *goanalysis.Linter { | ||
| return goanalysis.NewLinter( | ||
| "reuseconn", | ||
| "checks whether HTTP response body is consumed and closed properly in a single function", | ||
| []*analysis.Analyzer{reuseconn.Analyzer}, | ||
| nil, | ||
| ).WithLoadMode(goanalysis.LoadModeWholeProgram) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //golangcitest:args -Ereuseconn | ||
| package testdata | ||
| import ( | ||
| "io" | ||
| "io/ioutil" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Please use | ||
| "net/http" | ||
| ) | ||
| funcBodyNotDisposedInSingleFunction() { | ||
| resp,_:=http.Get("https://google.com")// want "response body must be disposed properly in a single function read to completion and closed" | ||
| _,_=ioutil.ReadAll(resp.Body) | ||
| resp.Body.Close() | ||
| } | ||
| funcBodyDisposedInSingleFunction() { | ||
| resp,_:=http.Get("https://google.com") | ||
| disposeResponse(resp) | ||
| } | ||
| funcdisposeResponse(resp*http.Response) { | ||
| ifresp!=nil&&resp.Body!=nil { | ||
| _,_=io.Copy(io.Discard,resp.Body) | ||
| _=resp.Body.Close() | ||
| } | ||
| } | ||