Skip to content

Go for Small Ops Tools

First PublishedByAtif Alam

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.

Use GoUse Bash or Python instead
Fast CLI with few dependenciesOne-off glue, aws CLI wrappers — Bash scripting
Concurrent HTTP checks or workersQuick data analysis — Python
Same binary on Linux amd64/arm64Team only knows Python

Download from go.dev or use a package manager:

Terminal window
brew install go # macOS

Verify:

Terminal window
go version
Terminal window
mkdir -p ~/src/helloctl && cd ~/src/helloctl
go mod init example.com/helloctl

main.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)
}
Terminal window
go run .
go build -o helloctl .
./helloctl -name=ops
  • go mod tidy — Add/remove requirements from imports.
  • go get package@version — Pin dependencies.
  • Private modules — Set GOPRIVATE for internal Git hosts.
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.

Terminal window
GOOS=linux GOARCH=amd64 go build -o helloctl-linux .

Go shines for small, distributable CLIs and concurrent network utilities. For infra definitions, still prefer Terraform and declarative config — see Terraform.