Let’s use go vet, the standard tool for analyzing Go’s source code

Image for post

Usage of Go is increasing within the company. Due to it being a compiler as well as a static type language, one of its key features is fast execution speed. Besides that, it is easy to learn due to its simple setup, easy enough that programs written using it can be run on multiple platforms.

With its increasing popularity, we foresee that more teams will begin to use Go. While preserving the quality of the code, in order to improve on serviceability, let’s use software to check the code… there are a few different types of software to choose from, but this time, we’d like to introduce go vet, software that is standardized for and built into Go.

how to use go vet

go vet is run by using the specification method go tool vet [directory].

After executing, areas with problems will be indicated in the output.

After that, just make the necessary edits to the source code according to the identified points.

Help

go vet’s help can be output using go doc cmd/vet.

Regarding options

Items for analysis can be designated in the options. By default, -all is selected, which will conduct a check on all items. For example, to search for unreachable code, use -unreachable.

Besides that, to change pointers to a numerical value, if you use unsafe.Pointer there is an option to show a warning -unsafeptr.

Although it’s basically alright to check all the items, please try to assign flags depending on requirements, and just execute the type of item/analysis that is required.

go vet is standardized, and will identify troublesome points based on previous experience. In short, the identified item is not always the problem. Nonetheless, it may also identify problems that did not show up in the compiler. By making edits alongside the contents, you should be able to write code that is easy to understand.

Many code analyzing tools for the Go language cause a heavy load on CPU resources. As such, it will take time when run on a local PC, and you might find it frustrating. When that happens, in coordination with Pull Request on GitHub, execute a Go language analytical tool, Sider, a CI service for automating code reviewing, should be of help. Sider is compatible with go vet. A free trial is available, so please try it first

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.