Go excels at CLIs—Docker, kubectl, Terraform, and gh are Go binaries. The standard library plus packages like flag and cobra (locally) build cross-platform tools with static linking.
flag package preview
name := flag.String("name", "world", "who to greet")
flag.Parse()
fmt.Println("Hello,", *name)
Compare with argparse in Python or picocli in Java—Go's single binary deploys without runtime installs.
Local workflow
go build -o mytool- Ship binary to Linux/macOS/Windows targets with GOOS/GOARCH cross-compile
- Embed version with
-ldflagsin CI
Important interview questions and answers
- Q: Why Go for CLIs?
A: Fast builds, static binaries, great stdlib for filesystem and network—easy distribution. - Q: Cross-compile?
A: SetGOOSandGOARCHenv vars—build Windows binary from macOS, etc.
Self-check
- Which stdlib package parses command-line flags?
- What env vars control cross-compilation?
Tip: Cross-compile with GOOS=linux GOARCH=amd64 go build—one codebase ships CLI binaries without runtime installs.
Interview prep
- Why Go for CLIs?
Static binaries, fast builds, cross-compile with GOOS/GOARCH—no runtime install on target.
- flag package?
Stdlib command-line flag parsing—cobra popular for larger CLIs locally.