closecheck

command module
v0.0.0-...-cfe3fda Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

closecheck

closecheck is a static code analyzer which checks whether a return value that implements io.Closer is correctly closed

Install

You can get closecheck by go get command.

$ go get -u github.com/dcu/closecheck

QuickStart

$ closecheck package/...

Analyzer

closecheck checks that a returned io.Closer is not ignored since that's a common cause of bugs and leaks in Go applications. Specially when dealing with *http.Response.Body

For example, the following code is reported as an error:

_, err := http.Get("https://www.google.com")
...

Because the response body must be closed.

The checker detects whether the returned struct has a field that implements io.Closer or not. In the previous case the *http.Response struct has a field called Body which implements io.Closer

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL