Go for Small Ops Tools
Go is a compiled language with a single static binary — convenient for CLI tools you ship to jump hosts, CI images, or bastions. This page is a minimal on-ramp; it complements the Prometheus Go client snippet in Exporters.
When Go Helps
Section titled “When Go Helps”| Use Go | Use Bash or Python instead |
|---|---|
| Fast CLI with few dependencies | One-off glue, aws CLI wrappers — Bash scripting |
| Concurrent HTTP checks or workers | Quick data analysis — Python |
| Same binary on Linux amd64/arm64 | Team only knows Python |
Install Toolchain
Section titled “Install Toolchain”Download from go.dev or use a package manager:
brew install go # macOSVerify:
go versionHello Module
Section titled “Hello Module”mkdir -p ~/src/helloctl && cd ~/src/helloctlgo mod init example.com/helloctlmain.go:
package main
import ( "flag" "fmt" "os")
func main() { name := flag.String("name", "world", "who to greet") flag.Parse() fmt.Fprintf(os.Stdout, "hello, %s\n", *name)}go run .go build -o helloctl ../helloctl -name=opsModules and Vendoring
Section titled “Modules and Vendoring”go mod tidy— Add/remove requirements from imports.go get package@version— Pin dependencies.- Private modules — Set
GOPRIVATEfor internal Git hosts.
HTTP Client (Sketch)
Section titled “HTTP Client (Sketch)”resp, err := http.Get("https://example.com/health")if err != nil { log.Fatal(err)}defer resp.Body.Close()if resp.StatusCode != http.StatusOK { log.Fatalf("status %d", resp.StatusCode)}Use context with timeouts for production tools.
Cross-Compile
Section titled “Cross-Compile”GOOS=linux GOARCH=amd64 go build -o helloctl-linux .Summary
Section titled “Summary”Go shines for small, distributable CLIs and concurrent network utilities. For infra definitions, still prefer Terraform and declarative config — see Terraform.