13. Build, Modules, & Tooling
Ship reproducible builds; manage private modules; wire linters/tests in CI; embed assets cleanly.
Q1 How do you work with private modules?
Answer: Set GOPRIVATE=github.com/yourorg/*, configure credentials (git/SSH), and optionally bypass proxy/sumdb for those modules.
Explanation: This ensures module downloads go directly to your VCS and prevents checksum DB leakage of private paths.
Q2 When would you use replace and vendoring?
Answer: Use replace for local development overrides or pinning forks; use vendoring for hermetic builds or restricted environments.
Explanation: Both are tooling controls to improve build reproducibility when needed.
Q3 What belongs in a Go CI pipeline?
Answer: go vet, golangci-lint/staticcheck, govulncheck, unit tests with -race, coverage thresholds, and go mod tidy checks.
Explanation: These steps catch correctness, security, and drift issues early.
Q4 How do you embed static assets into a Go binary?
Answer: Use //go:embed to embed files or directories into the binary.
Explanation: Embedded assets are exposed via embed.FS (implements fs.FS) and can be served with net/http or used by html/template.
import "embed"
//go:embed templates/*.html
var templatesFS embed.FS
// http.Handle("/", http.FileServer(http.FS(templatesFS)))
Q5 How do you inject build-time variables into a Go binary?
Answer: Use linker flags: -ldflags "-X pkgpath.var=value" on a package‑level string variable.
Explanation: Common for version, commit, and build date.
# main.go
# var version = "development"
go build -ldflags "-X main.version=$(git rev-parse --short HEAD)"
Q6 What is go generate and when should you use it?
Answer: go generate runs generator commands specified by //go:generate comments.
Explanation: Use it for code generation (mocks, stringers, assets). Keep it reproducible and documented.
Q7 What are module proxies, sumdb, and workspaces?
Answer: The module proxy caches modules; the checksum DB (sum.golang.org) verifies content; workspaces (go work) manage multi-module repos.
Explanation: Configure GOPROXY, GOSUMDB, and use go work use ./... to develop across modules.
Q8 What is Minimal Version Selection (MVS)?
Answer: MVS picks the minimum required version of each module that satisfies all requirements, avoiding SAT solving.
Explanation: Upgrading a module raises versions only along that path; others stay at their minimums unless required.