Golang / Golang Internals and Memory Management Interview Questions
What static analysis tools are essential for a Go project and what does each check?
Go's tooling ecosystem provides multiple layers of static analysis, from the built-in go vet to powerful third-party linters. Using them as part of CI prevents entire categories of bugs.
| Tool | Command | What it catches |
|---|---|---|
| go vet | go vet ./... | Misuse of Printf verbs, unreachable code, copying sync.Mutex, shadowed variables, incorrect struct tags |
| go build | go build ./... | Compile errors, unused imports, missing packages |
| go test -race | go test -race ./... | Data races — concurrent unsynchronised memory access |
| staticcheck | staticcheck ./... | Deprecated API use, performance issues, dead code, semantic bugs go vet misses |
| golangci-lint | golangci-lint run | Meta-linter running 50+ linters including vet, staticcheck, errcheck, gocritic |
| errcheck | errcheck ./... | Unchecked error return values (a very common Go bug source) |
| govulncheck | govulncheck ./... | Known vulnerabilities in dependencies (Go's official security scanner) |
// .golangci.yml â configuration for golangci-lint in CI # linters: # enable: # - govet # - staticcheck # - errcheck # - gosec # - misspell # - gofmt # - revive // Example: errcheck catches a common bug os.Remove(tmpFile) // BAD: ignoring error return if err := os.Remove(tmpFile); err != nil { // GOOD log.Println("cleanup failed:", err) } // go vet catches Printf format mismatches fmt.Printf("%d", "hello") // go vet: argument "hello" is a string, not int // govulncheck â check for known CVEs // go install golang.org/x/vuln/cmd/govulncheck@latest // govulncheck ./... // Vulnerability #1: GO-2023-1234 in github.com/vulnerable/pkg@v1.2.3 // Recommended CI pipeline: // 1. go build ./... // 2. go vet ./... // 3. go test -race -count=1 ./... // 4. golangci-lint run // 5. govulncheck ./...
More Related questions...