Golang

Go is the lingua franca of cloud-native infrastructure engineering, powering Kubernetes, Docker, Terraform, Prometheus, Envoy, and etcd. Its simple memory model, lightweight goroutines, and strict standard library make it exceptionally suited for high-throughput, low-latency microservices and distributed systems.

This section provides a 4-stage progressive roadmap comprising 26 comprehensive modules packed with practical, runnable code snippets, expected outputs, common production gotchas, and architectural design patterns.


The 4-Stage Go Roadmap

flowchart LR
    S1["Stage 1: Foundations & Core Syntax\n(Values, Pointers, Slices, Structs, Methods, Closures, Modules)"]
    S2["Stage 2: Type Safety, Generics & Text\n(Interfaces, Type Switches, Errors, Generics, Strings/Regex)"]
    S3["Stage 3: Concurrency & Synchronization\n(Channels, Sync/Atomics, Timers/Tickers, Context)"]
    S4["Stage 4: Systems, I/O, Networking & Production\n(Time/Crypto, Files/Embed, CLI/Slog, OS/Exec, JSON/XML, HTTP, Testing)"]

    S1 --> S2 --> S3 --> S4

Stage 1: Foundations & Core Data Structures (Simple)

Foundational syntax, control flow, functions, memory semantics, and collection layouts:

  1. 01: Variables, Constants, Control Flow & Enums
    Values, short variable declarations (:=), constants, for loops (4 styles), if/else branching, multi-case switch statements, and idiomatic enums with iota.
  2. 02: Functions, Pointers, Strings & Runes
    Multiple return values, variadic functions, recursion, value vs pointer semantics, memory addresses (&/*), and UTF-8 strings vs 32-bit integer runes.
  3. 03: Go Modules, Packages & Layout
    go.mod, go.sum, dependency management, visibility rules (capitalization), idiomatic project layout (cmd/, internal/, pkg/), and the init() function lifecycle.
  4. 04: Arrays, Slices & Maps in Go
    Fixed arrays vs 24-byte dynamic slice headers, pre-allocating capacity with make(), sub-slicing memory leaks, hash map mechanics, and the comma-ok idiom.
  5. 05: Structs, Constructors & Embedding
    Struct literals, constructor patterns (NewServer), functional options for configuration, and composition via struct embedding.
  6. 06: Methods: Value vs Pointer Receivers
    Value vs pointer receivers decision matrix, mutating struct fields, and calling methods on nil receiver pointers.
  7. 07: Closures, Scope & Defer in Go
    First-class functions, lexical closures, guaranteed resource cleanup with defer (LIFO execution), and the Go 1.22 loop variable scoping fix.

Stage 2: Interfaces, Generics & Text Processing (Easy–Medium)

Writing decoupled, testable code, parameterized types, and text manipulation:

  1. 08: Interfaces in Go: Implicit Satisfaction & Composition
    Implicit satisfaction, small single-method interfaces (io.Reader, io.Writer), interface composition, mock dependency injection, and the typed nil interface gotcha.
  2. 09: Type Assertions, Type Switches & any
    Comma-ok type assertions, multi-type switches (switch v := x.(type)), extracting JWT claims, and modern any vs legacy interface{}.
  3. 10: Idiomatic Error Handling: Wrapping, errors.Is & errors.As
    Errors as values, sentinel errors, contextual wrapping (fmt.Errorf %w), inspecting errors with errors.Is() and errors.As(), and panic/recover.
  4. 11: Generics in Go: Type Parameters, Constraints, Sorting & Iterators
    Type parameters [T any], comparable, cmp.Ordered, generic collections (Thread-safe Set), generic sorting (slices.Sort, slices.SortFunc), and Go 1.23+ range over iterators (iter.Seq).
  5. 12: Strings, Formatting, Templates & Regular Expressions
    The strings utility package, string formatting verbs (fmt.Sprintf), data-driven text generation with text/template, and regex pattern matching with regexp.

Stage 3: Concurrency & Synchronization (Medium)

Mastering Go’s CSP concurrency model, scheduling, and thread coordination:

  1. 13: Go Concurrency Architecture: Channels vs Mutexes
    Architectural overview, the Go runtime scheduler (M:N work-stealing), and the decision matrix for choosing between channels and mutexes.
  2. 14: Channels & Goroutines: Concurrency Patterns & Non-Blocking Select
    Unbuffered vs buffered channels, directional channels (chan<- / <-chan), select, non-blocking operations with default, worker pools, pipelines, and channel panic rules.
  3. 15: The sync Package: Mutex, RWMutex, WaitGroup, errgroup & Atomic Counters
    Protecting shared state with sync.Mutex and sync.RWMutex, coordinating goroutines with sync.WaitGroup, singletons with sync.Once, concurrent error handling with errgroup.Group, and lock-free atomic counters with sync/atomic.
  4. 16: Timers, Tickers, Rate Limiting & Stateful Goroutines
    One-shot timers, recurring tickers, bursty token bucket rate limiting, and stateful actor-style goroutines managing private state via dedicated request/response channels.
  5. 17: The context Package: Timeouts, Cancellation & Deadlines
    Context trees, context.Background() vs TODO(), timeouts with WithTimeout, manual aborts with WithCancel, and request-scoped metadata with WithValue.

Stage 4: Systems Programming, File I/O, Networking & Production Go (Medium)

Building robust, production-grade microservices and operating system utilities:

  1. 18: Time, Numbers, URLs, Hashes & Base64
    Wall clock vs monotonic clock, Unix epoch timestamps, Go’s reference time layout (2006-01-02 15:04:05), random numbers (math/rand/v2 and crypto/rand), number parsing (strconv), URL parsing (net/url), SHA-256 digests, and Base64 encoding.
  2. 19: Files, Directories, Line Filters & go:embed
    One-shot and buffered file reading/writing, line scanners (bufio.Scanner), cross-platform path manipulation (filepath), directory traversal with WalkDir, temporary files, and compiling static assets directly into binaries via //go:embed.
  3. 20: CLI Arguments, Environment Variables & Structured Logging
    Command-line arguments (os.Args), flags (flag), multi-command tools (flag.NewFlagSet), environment variable configuration, and high-performance structured JSON logging with log/slog.
  4. 21: OS Processes, Exec, Signals & Exit
    Spawning external commands (os/exec) with timeouts and pipes, process image replacement (syscall.Exec), trapping OS signals (signal.NotifyContext), and program exit codes.
  5. 22: JSON & XML Serialization with Struct Tags
    JSON/XML marshaling, struct tags (omitempty), streaming decoders (json.NewDecoder), custom MarshalJSON, and XML parsing (encoding/xml).
  6. 23: HTTP Servers, HTTP Clients, TCP Sockets & Graceful Shutdown
    Modern Go 1.22+ http.ServeMux routing, middleware chaining, production http.Client configurations, raw TCP socket listeners (net.Listen), and zero-downtime graceful shutdown with os/signal.
  7. 24: Struct & Request Payload Validation
    Validating API input with go-playground/validator, validation tags, custom cross-field rules, and clean HTTP 400 error formatting.
  8. 25: Reflection in Go: Runtime Introspection
    reflect.Type, reflect.Value, dynamic struct tag inspection, settability with Elem(), and reflection performance trade-offs.
  9. 26: Testing, Table-Driven Tests & Benchmarks
    Idiomatic table-driven unit tests (t.Run), testing HTTP handlers with httptest.NewRecorder, and CPU/memory allocation benchmarks with b.N.

Go by Example Topic Coverage Matrix

All 85 topics from Go by Example are mapped and fully covered across these 26 modules:

Go by Example TopicWiki Module Link
Hello World, Values, Variables, Constants, For, If/Else, Switch, Enums01: Variables, Constants & Control Flow
Functions, Multiple Return Values, Variadic Functions, Recursion, Pointers, Strings and Runes02: Functions, Pointers, Strings & Runes
Modules, Packages, Imports03: Go Modules, Packages & Layout
Arrays, Slices, Maps04: Arrays, Slices & Maps
Structs, Struct Embedding05: Structs & Embedding
Methods06: Methods
Closures, Range over Built-in Types07: Closures & Defer
Interfaces08: Interfaces
Type Assertions, Type Switches09: Type Assertions & Switches
Errors, Custom Errors10: Error Handling
Generics, Sorting, Sorting by Functions, Range over Iterators11: Generics
String Functions, String Formatting, Text Templates, Regular Expressions12: Strings, Templates & Regex
Concurrency Philosophy, Scheduler13: Concurrency Architecture
Goroutines, Channels, Channel Buffering, Channel Synchronization, Channel Directions, Select, Timeouts, Non-Blocking Channel Operations, Closing Channels, Range over Channels, Worker Pools14: Channels & Goroutines
Mutexes, WaitGroups, Atomic Counters15: Sync Package & Atomic
Timers, Tickers, Rate Limiting, Stateful Goroutines16: Timers, Tickers & Rate Limiting
Context, Cancellation, Deadlines17: Context
Time, Epoch, Time Formatting / Parsing, Random Numbers, Number Parsing, URL Parsing, SHA256 Hashes, Base64 Encoding18: Time, Numbers, URLs & Crypto
Reading Files, Writing Files, Line Filters, File Paths, Directories, Temporary Files and Directories, Embed Directive19: Files, Directories & Embed
Command-Line Arguments, Command-Line Flags, Command-Line Subcommands, Environment Variables, Logging20: CLI, Env & Logging
Spawning Processes, Exec’ing Processes, Signals, Exit21: OS Processes & Exec
JSON, XML22: JSON & XML
HTTP Client, HTTP Server, TCP Socket Server, Graceful Shutdown23: HTTP & Graceful Shutdown
Struct & Request Payload Validation24: Validators
Reflection25: Reflection
Testing and Benchmarking26: Testing & Benchmarks

26 items under this folder.