← All insightsCheat Sheet

Go for DevOps cheat sheet: the complete command reference

CodeWizard Engineering · 6 October 2025 · 3 min read · Beginner

This is a complete, hands-on Go for DevOps cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.

Go is a statically typed, compiled language behind Kubernetes, Docker, Terraform and most cloud-native tooling. Its single static binaries and strong concurrency make it ideal for CLIs, controllers and operators.

Why you reach for it

  • Single static binary - trivial to distribute
  • Fast builds and great concurrency primitives
  • The native language of the cloud-native ecosystem

Installation

bash
# install via your package manager or from go.dev/dl
go version
go mod init github.com/acme/tool

Configuration reference

A tiny HTTP health server with graceful shutdown.

go
package main

import (
  "net/http"
  "log"
)

func main() {
  http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("ok"))
  })
  log.Fatal(http.ListenAndServe(":8080", nil))
}

Core commands you use daily

bash
go build ./...
go test ./... -race
GOOS=linux GOARCH=amd64 go build -o tool .

Build, test, modules

bash
go mod init github.com/acme/tool
go mod tidy
go build ./...
go test ./... -race -cover
go vet ./...
govulncheck ./...

Cross-compile

bash
GOOS=linux GOARCH=amd64 go build -o tool-linux .
GOOS=darwin GOARCH=arm64 go build -o tool-mac .
CGO_ENABLED=0 go build -ldflags='-s -w' -o tool .

Use it in CI/CD

Build, vet and test in CI.

yaml
- uses: actions/setup-go@v5
  with: { go-version: '1.22', cache: true }
- run: go vet ./... && go test ./... -race -cover

Best-practice checklist

  • Always check and wrap errors with context
  • Use context.Context for cancellation and timeouts
  • Run go vet, staticcheck and -race in CI

Common pitfalls to avoid

  • Ignoring returned errors
  • Goroutine leaks from missing context cancellation
  • Giant main packages instead of small, testable ones

Security quick wins

  • Run govulncheck to find vulnerable dependencies
  • Build minimal/distroless images for Go binaries

Works well with

  • Python for DevOps - The glue language of DevOps - automation scripts, CLIs, API clients and operators.
  • Bash & Shell Scripting - The universal glue on every Linux box - with a few rules it becomes safe and reliable automation.
  • Kubernetes - Declarative orchestration for containers at scale - self-healing, rolling updates and service discovery.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.

Want senior help putting Go for DevOps to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult