The go vet tool
The go vet
tool is used for static analysis of your Go code. While the Go compiler can find and inform you of mistakes you may have made, there are certain things it will miss. For this reason, the go vet
tool was created. This might sound trivial, but some of these issues could go unnoticed for a long time after the code has been deployed, the most common of which is passing the wrong number of arguments when using the Printf
function. It will also check for useless assignments, for example, if you set a variable and then never use that variable. Another particularly useful thing it detects is when a non-pointer interface is passed to an unmarshal
function. The compiler won’t notice this as it is valid; however, the unmarshal
function will be unable to write the data to the interface. This can be troublesome to debug but using the go vet
tool allows you to catch it early and remediate the issue before it becomes a problem.