Toolchain and CI

Contents
gofmt -l in CI
vet before merge
go mod tidy
A minimal CI script

gofmt -l in CI

Go ships one official format, so teams never debate tabs against spaces. The gofmt tool rewrites files into that format, and the l flag lists files that still need formatting without touching them.

The session below finds one unformatted file, fixes it in place with the w flag, and confirms that the second listing stays silent. Silence means every file is clean.

gofmt -l .

main.go

gofmt -w main.go

gofmt -l .

(no output: every file is clean)

vet before merge

The vet tool hunts suspicious code that still compiles. It checks print format strings against arguments, flags unreachable code, and spots common mistakes with locks, shifts, and struct tags.

Run vet over the whole module before every merge. An empty result means vet is happy, while any report deserves a fix rather than a suppression comment.

go vet ./...

(no output: vet is happy)

go mod tidy

The go.mod file lists module dependencies, and real code drifts away from it over time. The tidy command adds missing requirements, drops unused ones, and keeps go.sum in sync.

Run tidy after adding or removing imports, then build the whole module. Both commands stay silent on success, which is exactly the result a clean tree should produce.

go mod tidy

(no output: go.mod and go.sum are in sync)

go build ./...

(no output: the build passes)

A minimal CI script

Continuous integration repeats the same checks on every push that developers run locally. The workflow below installs Go, then runs format, vet, and tests in the same order as this lesson.

Keep the script short at first and extend it later with lint, benchmarks, or release jobs. A short script that always runs beats a grand pipeline that stays disabled.

cat .github/workflows/go.yml

name: go

on: [push]

jobs:

build:

runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v4

- uses: actions/setup-go@v5

- run: gofmt -l .

- run: go vet ./...

- run: go test ./...

go test ./...

ok wordfreq 0.012s

Next: Project layout

Article author: Arthur Isaev

Related articles
Golang
Go course: zero to hero in 50 lessons
What is Go and where it runs
Install Go and check the version
Your first Go program
Modules with go mod
Variables
Constants
Types
Numbers
Strings
Conditions with if
Switch in Go
Loops with for
Arrays in Go
Slices in Go
Maps in Go
Functions in Go
Errors as values
Pointers in Go
Structs in Go
Methods in Go
Interfaces in Go
Embedding instead of inheritance
Generics in Go
Packages and imports
The go toolchain
Testing with go test
Advanced errors
defer in Go
Strings, bytes and runes
Time in Go
JSON
Files and IO
HTTP servers
HTTP clients
Context
Goroutines
Channels
select and sync
CLI: args, flags, env
Logging
Regular expressions
Sorting
Concurrency patterns
Databases with database/sql
Benchmarks and profiling
Toolchain and CI
Project layout
Capstone: wordfreq CLI
Capstone: JSON API server
Hero roadmap: the whole course on one page
Install Go on Windows 11
Install Go on Ubuntu
Install Go on Rocky Linux
Install Go on macOS
Install Go on FreeBSD
Go in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: