go vet: Static Checks Gate in CI
go vet runs a suite of static analyzers (printf formatting, struct tags, lost cancel, and more) and exits non-zero when it finds a problem.
vet catches real bugs the compiler does not, like a Printf with the wrong verb. It is a fast CI gate, and go test runs a subset of vet automatically before tests.
What it does
go vet builds the packages and runs analyzers over them. You can enable a single analyzer with its flag (for example -printf or -structtag) or disable one by setting it false (-printf=false). Passing a specific analyzer flag runs only that analyzer.
Common usage
go vet ./...
go vet -printf=false ./... # disable the printf analyzer
go vet -structtag ./... # run only struct-tag checks
go test -vet=off ./... # skip vet during go testFlags
| Flag | What it does |
|---|---|
| ./... | Vet all packages in the module |
| -printf | Run only the Printf format analyzer |
| -printf=false | Disable the Printf analyzer |
| -structtag | Check struct field tags for validity |
| -vet=off (go test) | Turn off the automatic vet pass before tests |
| -tags <list> | Apply build tags while vetting |
In CI
Run go vet ./... as a quick gate before the test suite. It uses the Go build cache, so cache GOCACHE and the module cache. Because go test already runs a high-confidence vet subset, a separate go vet step adds the analyzers test mode skips. golangci-lint bundles vet plus more if you want a single linter.
Common errors in CI
"Printf format %d has arg x of wrong type string" is the classic vet failure. "struct field tag json:foo not compatible with reflect.StructTag.Get: bad syntax" comes from -structtag. "the cancel function returned by context.WithCancel should be called, not discarded, to avoid a context leak" is the lostcancel analyzer. "# command-line-arguments" prefixes vet errors on ad hoc file sets.