Back

Go Vet Command and Its Usage

The Golang vet command is a built-in tool that is included in the Go programming language. It is designed to help developers identify and diagnose potential problems in their Go code. This can be useful for catching errors before they are compiled, ensuring that the code is as clean and efficient as possible.

Go vet command is a handy tool that can help you write better and cleaner code. It helps you find errors in your application and reports suspicious constructs such as abnormal or useless code, as well as detect common mistakes using different packages.

Vet command (or should we say vet commands?) is a collection of different analysis tool commands and sub-analyzers. It is worth mentioning that vet uses heuristics which can’t guarantee that 100% of the reports will be genuine issues. However, it can detect errors that compliers might omit.

Using the vet command

You can invoke vet with the go command. The following command will vet the current directory package:

go vet

If you wish to vet a package in another directory you need to provide a path:

go vet my_machine/project/...

If you want to vet specific packages you can use:

go help packages

Listing all available checks with tool vet help

You can list all available checks by running the:

go tool vet help

Now, let’s briefly go over what you can exactly get from the go tool vet help commands.

asmdecl

asmdecl reports mismatches between the Go declarations and assembly files.

assign

This is a check for useless assignments.

atomic

This is for common mistakes using the sync/atomic package and will check any irregularities in the usage of the atomic function.

bools

Detects common mistakes that involve boolean operators.

buildtag

Checks the form and location of the +build tags. The +build flags supported by go vet are related to the resolution and execution of the control package.

cgocall

Checks for violations of the cgo pointer passing rules.

composites

Looks for any composite literals using unkeyed fields.

copylocks

Detects copied locks passed by value as an error. The locks should never be copied, as the copy of the lock will copy the internal state of the “original” making it the same as the “original”.

httpresponse

Checks for any mistakes in HTTP responses usage

loopclosure

Checks for any references to loop variables from within nested functions.

lostcancel

Detects cancel func that is returned by context.WithCancel. Creating a cancellable context will return a new context with a function that enables you to cancel that particular context. You can use that function to cancel each and every operation linked to that context, however, it has to be called in order. Otherwise, it will leak context.

nilfunc

Searches for useless comparisons between nil and functions.

printf

Checks for consistency in Printf format. Constructs such as Printf calls with arguments that don’t align with the format string will be flagged.

shift

This go vet analysis tool will try to find shifts that either exceed or equal the integer width.

stdmethods

Checks for methods that you have implemented from the standard library interfaces and their compatibility.

structtag

Detects fields that don’t conform to the convention defined in the reflect package.

tests

This analyzer catches likely mistakes made while using either a test or an example.

unmarshal

It returns all instances of passing non-interface or non-pointer values to unmarshal.

unreachable

Simply checks for any code that is unreachable.

unsafeptr

Detects any invalid conversion of uintptr to unsafe.Pointer.

unusedresults

Detects unused results of calls to functions.

Conclusions on the go vet analysis tool

Go vet is a very useful collection of tools that can help you find different issues with your source code. By design, all checks are performed, unless any flags are set to true. In that case, only those tests will be run. Analogically, setting a flag to false will disable that particular test.

Please mind that not all returned errors are genuine problems. Moreover, if you wish to look for other subtle issues in your go programs, one that no specific checker detects, there is an option to add additional checks and custom analyzers.

 

Type casting is a technique used in programming to convert one data type to another and is essential in statically typed languages like Golang, which require explicit type conversion.

Written by Janusz

The Golang vet command is a built-in tool that is included in the Go programming language. It is designed to help developers identify and diagnose potential problems in their Go code. This can be useful for catching errors before they are compiled, ensuring that the code is as clean and efficient as possible.

Written by Janusz

Go 1.18 released in the first half of 2022 was probably the biggest update in Golang’s history. Google themselves called it a milestone in the development of the Golang programming language that can be considered a culmination of the last 10 years of design and development efforts.

Written by Janusz

Golang type aliases were introduced in Go version 1.9 and have been available since. Type alias declaration has a different form from the standard type definition and can be particularly helpful during code refactoring but can also have other uses.

Written by Janusz

Found 8 Results
Page 1 of 1

Golang Cast: Go Type Casting and Type Conversion


Type casting is a technique used in programming to convert one data type to another and is essential in statically typed languages like Golang, which require explicit type conversion.

golang cast

March 30, 2023-


Go Vet Command and Its Usage


The Golang vet command is a built-in tool that is included in the Go programming language. It is designed to help developers identify and diagnose potential problems in their Go code. This can be useful for catching errors before they are compiled, ensuring that the code is as clean and efficient as possible.

go vet command

December 5, 2022-


How The Biggest Ever Go Update Brought Native Fuzzing


Go 1.18 released in the first half of 2022 was probably the biggest update in Golang’s history. Google themselves called it a milestone in the development of the Golang programming language that can be considered a culmination of the last 10 years of design and development efforts.

How the Biggest Ever Go Update Brought Native Fuzzing

November 2, 2022-


Golang Type Alias


Golang type aliases were introduced in Go version 1.9 and have been available since. Type alias declaration has a different form from the standard type definition and can be particularly helpful during code refactoring but can also have other uses.

golang type alias

October 25, 2022-


Python vs. Golang. Features, Pros, Cons, and Areas of Use


Both Golang and Python are fantastic programming languages, each in its way. We examine their strengths, weaknesses, and areas of use to help you figure out how you can leverage them for your business goals.  

python vs golang

October 12, 2022-


What is Golang?


Golang (or Go in short) is a breath of fresh air in the coding market. A long-needed shakeup in the stale programming market with a cute gopher as a mascot. Its development was started in 2007 by designers Robert Griesemer, Rob Pike, and Ken Thompson.

April 27, 2022-


What are the best frameworks for Golang REST API?


As using a framework is completely optional, you’re probably wondering: should I even use one? 

April 21, 2022-


Golang vs Java comparison. Why are more and more companies moving from Java to Golang?


Everyone knows Java, but do you know Golang? Golang (or G in short) started development in 2007 and was published in 2009 by Google as an open-source programming language.


Page 1 of 1