Go Tutorial with Examples.
Go tutorial with runnable examples: cloud-native Go for distributed systems, Kubernetes tooling, DevOps automation and high-concurrency backend services.
Beginner
Start here — no prior experience needed
Introduction to Go
What Go is and why it is used for cloud tools and CLIs, with a first program, a goroutine and a single static binary, each run with its real output.
Setting Up Go
Install Go and start a real module: go mod init, go run with arguments, go get, gofmt and go vet, and cross-compiling, each with its actual output.
Variables in Go
Go variables run for real: var vs :=, zero values, the unused-variable compile error, multiple assignment and swaps, iota constants, and := shadowing.
Data Types in Go
Go's basic types run for real: integer overflow, float precision and NaN, strings vs bytes vs runes, explicit conversions, strconv, and defined types.
Operators in Go
Go operators run for real: integer division and modulo signs, ++ as a statement, short-circuit logic, bit flags with &^, and why there is no ternary.
Control Flow in Go
Go control flow run for real: if with an init statement, switch without fallthrough, the single for loop, range, and labelled break and continue.
Functions in Go
Go functions run for real: multiple and named returns, variadic calls, closures and the loop-variable change, defer order and arguments, and init.
Strings in Go
Go strings run for real: immutability, the strings package, Sprintf verbs, Builder vs += allocations, reversing by rune, Replacer, and regexp.
Arrays and Slices in Go
Go arrays and slices run for real: value vs view semantics, len and cap growth, append aliasing bugs, copy, deleting, 2D slices, and the slices package.
Maps in Go
Go maps run for real: comma-ok lookups, the nil-map panic, random iteration order, struct values you can't assign, sets, and a concurrent-write crash.
Structs in Go
Go structs run for real: literals and zero values, value vs pointer receivers, constructors, embedding and promotion, JSON tags, comparison, and padding.
Packages and Modules in Go
Go packages and modules run for real: a multi-package module, exported names, the internal/ rule, replace and go.work, import cycles, and go doc output.
Intermediate
For developers with core concepts down
Interfaces in Go
Go interfaces run for real: implicit satisfaction, pointer-receiver method sets, type assertions and switches, Stringer, io.Reader, and the nil trap.
Error Handling in Go
Go errors run for real: errors as values, wrapping with %w vs %v, errors.Is and errors.As through a chain, custom types, errors.Join, and panic vs recover.
Goroutines in Go
Goroutines run for real: main exiting early, sync.WaitGroup, collecting results in order, a data race caught by -race, a goroutine panic, and GOMAXPROCS.
Channels in Go
Go channels run for real: unbuffered handoff, deadlocks, buffers, close and range, directional types, select with default and timeouts, and nil channels.
Concurrency Patterns in Go
Go concurrency patterns run for real: worker pools, bounded fan-out pipelines, context timeouts and cancellation, RWMutex, sync.Once, and errgroup limits.
File I/O in Go
Go file I/O run for real: os.ReadFile and WriteFile, bufio.Scanner and its 64 KB line limit, a missing Flush, appending, walking directories, and JSON.
Testing in Go
Go testing run for real: a failing test, table-driven subtests, t.Error vs t.Fatal, httptest, examples, fuzzing that finds a bug, benchmarks, and coverage.
HTTP Server in Go
A Go HTTP server run for real with curl: ServeMux patterns and the catch-all /, method routing, a JSON API, middleware, request context, graceful shutdown.
CLI Tools in Go
Go command-line tools run for real: the flag package and -h, stdin pipes, stdout vs stderr, exit codes and os.Exit, env vars, subcommands, and cobra.
Advanced
Production-grade patterns for experienced engineers
Generics in Go
Go generics run for real: type parameters, inference, comparable and cmp.Ordered, ~ constraints, generic types, generic methods (Go 1.27), and iter.Seq.
Memory Management in Go
Go memory run for real: escape analysis with -gcflags=-m, counting allocations, gctrace and GOGC, sync.Pool and preallocation benchmarks, pprof, a leak.
Design Patterns in Go
Idiomatic Go patterns run for real: functional options, HTTP middleware chains, a repository interface, constructor injection with a fake, and events.
Go Interview Preparation
Top 35 Go interview questions and answers covering goroutines, channels, interfaces, memory, the scheduler, and common coding problems.
Also part of Go
Taught in other topics. Each link opens the lesson in its home topic.
Design Patterns That Are Just Language Features: Strategy, Command, Iterator
Strategy becomes a function, Command a closure, Iterator a generator, run in Python, Java 21 and Go 1.23, with the cases where the class should stay.
Multi-Stage Builds
Use multi-stage Dockerfiles to produce small, secure production images by separating build and runtime environments.