🧰 The DevOps Engineer’s 80/20 Golang Cheat Sheet

As a DevOps engineer, I’m always looking for tools that help automate, integrate, or just get out of the way. Go (Golang) is one of those tools. It powers many of the systems we use every day—Terraform, Docker, Kubernetes, Helm, and more. But if you're anything like me, you might be wondering:

“What’s the minimum I need to know to get the most value from Go as a DevOps engineer?”

This is where the 80/20 rule kicks in. Let’s skip the theory-heavy stuff and focus on the 20% of Go knowledge that delivers 80% of the impact in DevOps workflows.


Why Should DevOps Engineers Learn Go?

Because most of our tooling is written in it. Learning Go lets you:

  • Read and tweak existing open-source tools
  • Build small command-line utilities
  • Understand and debug infrastructure code
  • Automate tasks that are too messy for Bash

🔧 Go: The DevOps Cheat Sheet

Here’s a focused crash course on what actually matters.


🏁 Basic Program Structure

package main

import (
    "fmt"
    "os"
)

func main() {
    fmt.Println("Hello DevOps")
    fmt.Println("Args:", os.Args[1:])
}

🛠 CLI Flags

import "flag"

func main() {
    env := flag.String("env", "dev", "Environment")
    dryRun := flag.Bool("dry-run", false, "Dry run mode")
    flag.Parse()

    fmt.Println("Env:", *env, "Dry Run?", *dryRun)
}

📁 Read a File

data, err := os.ReadFile("/etc/config.yaml")
if err != nil {
    log.Fatal(err)
}
fmt.Println(string(data))

🌍 Make an HTTP Request

import (
    "net/http"
    "io/ioutil"
)

resp, err := http.Get("https://api.example.com")
if err != nil {
    log.Fatal(err)
}
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))

🔄 Parse JSON

type Config struct {
    Name string `json:"name"`
    Port int    `json:"port"`
}

var c Config
json.Unmarshal([]byte(`{"name":"web","port":8080}`), &c)
fmt.Println(c.Name)

🧪 Unit Test (Yes, You Should)

func Add(a, b int) int { return a + b }

func TestAdd(t *testing.T) {
    result := Add(2, 3)
    if result != 5 {
        t.Errorf("Expected 5, got %d", result)
    }
}

🛠 Real DevOps Use Cases for Go

✅ Task🚀 Go Feature/Tool
Build CLI toolsflag, cobra, urfave/cli
Talk to APIsnet/http, encoding/json
Parse YAML/JSON configsgopkg.in/yaml.v2 / stdlib
Automate AWS via SDKaws-sdk-go
Write testable small toolstesting, interfaces
Format & lintgo fmt, go vet, staticcheck

🛠 Tools You Already Use (Written in Go)

  • Terraform
  • Kubectl
  • Helm
  • Docker CLI
  • Prometheus
  • Consul
  • Vault

If you’ve ever said “I wish I could tweak this tool,” knowing Go gives you that power.


💡 DevOps Mini Project Ideas

  • CLI to restart AWS EC2 instances by tag
  • Script to pull env vars from docker inspect
  • Kubernetes manifest linter
  • Wrapper for kubectl that filters pods by readiness or age

Final Thoughts

Learning Go isn’t about building massive applications. It’s about augmenting your DevOps toolkit, writing just enough code to make your life easier, and understanding the tools you rely on.

With a little Go knowledge, you can go a long way (pun intended).

If you're interested, I’ll post a follow-up where I build one of the mini projects above, probably the EC2 restart tool. Let me know which one you’d like to see!

🚀 Join the DevOps Dojo! 🌟

Are you passionate about growth, learning, and collaboration in the world of DevOps? The DevOps Dojo is your new home! Whether you’re just starting out or looking to refine your skills, this vibrant community is here to support your journey.

🔧 What You’ll Get:

  • Access to expert-led discussions
  • Hands-on learning opportunities
  • Networking with like-minded professionals

Ready to take your DevOps game to the next level? Click below to learn more and join the community!

👉 Join the DevOps Dojo Today

Let’s build, grow, and thrive together! 🌐

Leave a Comment