liveBook · Manning

Go vet

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

go vet is a Go distribution tool that reports suspicious constructs in Go source code through static analysis.

go vet is Go’s fast static-analysis command for finding suspicious source constructs before they become bugs or consume reviewer time. Run it across all packages with `go vet ./...`. section 5.4

Catching a formatting bug

An incorrect `fmt.Sprintf` call passes more arguments than its format string expects. Running `go vet ./...` reports the mismatch, providing specific feedback before tests run. section 5.4

go vet ./...

Use this command to check every package in the repository. section 5.4

Listing 5.6 pipeline.yml
vet:
    name: Check formatting
    runs-on: ubuntu-latest
    steps:
    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.18
    - name: Check out code into the Go module directory
      uses: actions/checkout@v2
    ...
    - name: Vet
      run: go vet ./...     #1

Add a vet job after formatting checks and before tests so the pipeline filters inexpensive, actionable problems early. section 5.4

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Defines static analysis, demonstrates a format-argument failure, and shows CI placement without detailing vet’s internal checks.
Examples
Uses `go vet ./...`, an incorrect `fmt.Sprintf` call, and a pipeline job as concrete teaching artifacts.
What it assumes
Assumes Go source and an existing formatting-and-testing workflow, while introducing the vet command through a first run.
What you can do after
Operate/configure `go vet` across packages and place it before tests in an automated pipeline.
How it connects
Connects static analysis with formatting checks, testing, continuous integration, and broader linting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.