# Go Structure Quick Reference

## Build Analysis Commands

| Command | Shows |
|---------|-------|
| `time go build ./...` | Total build time |
| `go build -v ./...` | Package compilation order |
| `go build -x ./...` | Exact commands executed |
| `go clean -cache && go build ./...` | Cold build time |
| `go list -m all \| wc -l` | Total dependency count |
| `go mod graph` | Full dependency graph |
| `go mod why -m <pkg>` | Why a dependency exists |
| `go mod tidy` | Remove unused deps |

## init() Pattern

| Signal | Action |
|--------|--------|
| `init()` opens DB/network | Replace with `sync.Once` lazy init |
| `init()` reads config files | Replace with lazy init or explicit call in main |
| `init()` registers types | Usually OK (cheap, one-time) |
| `init()` sets package vars | OK if no I/O or computation |
| `init()` panics on error | Replace with error-returning function |

## Package Dependency Metrics

| Metric | Command | Threshold |
|--------|---------|-----------|
| Fan-in (imports of pkg) | `go list -f '...' ./... \| sort \| uniq -c \| sort -rn` | >10 = god package candidate |
| Fan-out (pkg imports) | `go list -f '{{len .Imports}}' ./pkg` | >20 = too many deps |
| Circular deps | `go vet ./...` | Must be zero |
| CGo packages | `grep -r 'import "C"'` | Minimize |
