gofmt là formatter chính thức của Go, chuẩn hóa indentation (tab), spacing, và cú pháp. Không có option cấu hình — một chuẩn duy nhất cho toàn bộ cộng đồng Go. Chạy: gofmt -w .
goimports = gofmt + tự động thêm/xóa import statements. Đây là công cụ được khuyến nghị dùng trong editor (VS Code, GoLand) thay thế gofmt.
goimports -w . # format + fix imports
goimports -l . # chỉ list files cần fixgolangci-lint là meta-linter chạy hàng chục linters song song: staticcheck (bugs tiềm ẩn), errcheck (bỏ sót check error), govet (misuse of sync primitives), revive (code style), gosec (security), v.v.
golangci-lint run ./...
golangci-lint run --fix ./... # tự fix một số issuesCấu hình qua .golangci.yml:
linters:
enable:
- errcheck
- staticcheck
- gosimple
- unused
- reviveBest practice: tích hợp goimports vào editor (save hook), chạy golangci-lint trong CI pipeline và fail build nếu có lỗi.
gofmt is Go's official formatter: normalizes indentation (tabs), spacing, and syntax. Zero configuration — one style for the entire community.
goimports = gofmt + automatically adds/removes import statements. Recommended as the editor save-hook formatter (replaces gofmt directly).
golangci-lint is a meta-linter running dozens of linters in parallel: staticcheck (latent bugs), errcheck (unchecked errors), govet (sync misuse), revive (code style), gosec (security), etc.
golangci-lint run ./... # lint everything
golangci-lint run --fix ./... # auto-fix where possibleBest practice: configure goimports as the editor on-save hook; run golangci-lint in CI and fail the build on any finding.