Stop 05 · Scripting & Programming for DevOpsTopics · 7/8

Go Basics (Overview)

Part of the DevOps Roadmap

In short

Docker, Kubernetes, Terraform and Prometheus are all written in Go. You don't need to become a Go developer, but reading it helps you understand tool errors, and it's great for small, fast CLIs.

Many core DevOps tools (Docker, Kubernetes, Terraform) are written in Go — a basic conceptual familiarity helps you read tool source code and understand error messages, even without becoming a Go developer.

The mascot in a hostel room dips a sealed meal pouch into a small pot of hot water.

Think of it like this

The ready-to-eat meal packet

A ready-to-eat dal-rice packet has everything sealed inside. No need to buy masala or check if the hostel has the right utensils. Just heat and eat, anywhere. A Go program compiles into one binary with everything inside: copy it to any Linux box and run it.

Watch it happen

From main.go to a running tool

main.go
go build
One binary
Any server

1/4You write a small health-check tool in main.go using only the standard library.

The big ideas

What you need to know

Single static binaries

Go tools usually ship as one file. That's why installing kubectl or terraform is often just a download.

Errors are values

Functions return an error alongside the result, and code checks if err != nil right away. You'll see this everywhere.

Fast and concurrent

Goroutines make it easy to do many things at once, like checking 100 servers in parallel.

Read before you write

Start by reading Go tool source and error messages. Writing your own CLI can come later.

See it in code

Walk through the code

go
1package main2 3import (4	"fmt"5	"net/http"6	"os"7)8func main() {9	resp, err := http.Get("https://example.com/health")10	if err != nil {11		fmt.Fprintln(os.Stderr, "request failed:", err)12		os.Exit(1)13	}14	defer resp.Body.Close()15	fmt.Println("status:", resp.Status)16}

1/3Every runnable Go program is package main, and imports only what it uses.

Run it with go run main.go, or build a binary with go build -o healthcheck. gofmt would add a blank line before func; it's trimmed here to fit.

Save yourself the pain

Common mistakes

Oops

Ignoring the err value with _ to make the code shorter.

Do this instead

Check every error. Go makes failures explicit on purpose, and ignoring them hides real problems.

Oops

Thinking you must master Go before working in DevOps.

Do this instead

Reading Go is enough at first. Python and Bash cover most daily automation.

Your mission

Build your first binary

~30 min

Quick check

Why are many DevOps tools easy to install on any server?

Go deeper

  1. 1Read through a short Go tutorial to understand its basic syntax and philosophy.
  2. 2Skim the source of a small open-source Go-based DevOps tool to see how it's structured.
  3. 3Understand you don't need to write Go fluently — recognizing it helps far more than mastery does.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge