@@ -26,6 +26,7 @@ const (
26
26
Doc = "bodyclose checks whether HTTP response body is closed successfully"
27
27
28
28
nethttpPath = "net/http"
29
+ closeMethod = closeMethod
29
30
)
30
31
31
32
type runner struct {
@@ -70,7 +71,7 @@ func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
70
71
bodyItrf := bodyNamed .Underlying ().(* types.Interface )
71
72
for i := 0 ; i < bodyItrf .NumMethods (); i ++ {
72
73
bmthd := bodyItrf .Method (i )
73
- if bmthd .Id () == "Close" {
74
+ if bmthd .Id () == closeMethod {
74
75
r .closeMthd = bmthd
75
76
}
76
77
}
@@ -156,15 +157,14 @@ func (r *runner) isopen(b *ssa.BasicBlock, i int) bool {
156
157
}
157
158
vrefs := * v .Referrers ()
158
159
for _ , vref := range vrefs {
159
- switch vref := vref .(type ) {
160
- case * ssa.UnOp :
160
+ if vref , ok := vref .(* ssa.UnOp ); ok {
161
161
vrefs := * vref .Referrers ()
162
162
if len (vrefs ) == 0 {
163
163
return true
164
164
}
165
165
for _ , vref := range vrefs {
166
166
if c , ok := vref .(* ssa.Call ); ok {
167
- if c .Call .Method .Name () == "Close" {
167
+ if c .Call .Method .Name () == closeMethod {
168
168
return ! called
169
169
}
170
170
}
@@ -270,10 +270,8 @@ func (r *runner) isCloseCall(ccall ssa.Instruction) bool {
270
270
closeMtd := ccall .Type ().Underlying ().(* types.Interface ).Method (0 )
271
271
crs := * ccall .Referrers ()
272
272
for _ , cs := range crs {
273
- switch cs := cs .(type ) {
274
- case * ssa.Defer :
275
- switch val := cs .Common ().Value .(type ) {
276
- case * ssa.Function :
273
+ if cs , ok := cs .(* ssa.Defer ); ok {
274
+ if val , ok := cs .Common ().Value .(* ssa.Function ); ok {
277
275
for _ , b := range val .Blocks {
278
276
for _ , instr := range b .Instrs {
279
277
if c , ok := instr .(* ssa.Call ); ok {
0 commit comments