Skip to Content
Skip to content
PROGRAMMING

Go Tutorials

Standalone Go tutorials covering concrete runtime traps and service patterns: slice backing-array aliasing, nil-map panics, typed-nil interfaces, context.Context timeouts, worker pools, go test -race data races, pprof allocations, and static binaries under 10 MB.

Each guide pairs a small runnable Go program with its exact compiler, test, or benchmark output so you can verify the behavior locally.

Go
Fix "assignment to entry in nil map" in Go Level: Beginner

Reproduce Go's nil map panic, initialize maps with make or literals, and guard struct map fields safely. After this, map writes never crash on zero-value structs.

Go
Why Go append Mutates Another Slice (and How to Stop It) Level: Beginner

See why two Go slices overwrite each other after append and prevent it with full-slice expressions or slices.Clone.

Go
Why Unexported Go Struct Fields Stay Empty in encoding/json Level: Beginner

Fix Go structs that decode to zero values in json.Unmarshal and catch misspelled JSON keys with DisallowUnknownFields.

Go
Test a Go net/http Handler Without Starting a Server Level: Beginner

Use net/http/httptest to send JSON requests, check status codes, and test validation paths in memory. After this, you can test HTTP handlers in milliseconds without opening a port.

Go
Compile a Static Go Binary Under 10 MB Level: Beginner

Compare default go build output against CGO_ENABLED=0 with -trimpath and -ldflags="-s -w", and check shared library links with ldd.

Go
Find and Fix Go Data Races With -race Level: Advanced

Trigger a real data race under go test -race, read the race detector output, and fix shared counters, maps, and slice writes using atomic, sync.Mutex, and disjoint indices.

Go
Benchmark Speed and Heap Allocations With go test -bench -benchmem Level: Advanced

Measure nanoseconds and heap allocations with testing.B and -benchmem, compare += vs strings.Builder, pre-size slices, and reuse buffers with sync.Pool.

Go
Embed Static Files and Build Versions Into a Go Binary Level: Advanced

Bundle static files with //go:embed and embed.FS, serve subdirectories cleanly with fs.Sub, and inject version strings with -ldflags -X or debug.ReadBuildInfo.

Go
Why a Typed Nil Pointer Is Not == nil in Go Interfaces Level: Intermediate

Reproduce Go's typed-nil interface trap with custom errors and io.Writer, see why w == nil returns false, and fix return paths cleanly.

Go
Add Context Deadlines to Outbound HTTP Calls in Go Level: Intermediate

Replace http.Get with http.NewRequestWithContext, combine Client.Timeout with per-call context.WithTimeout, and detect DeadlineExceeded cleanly.

Go
Replace fmt.Println With Structured JSON Logging in Go (log/slog) Level: Intermediate

Switch from fmt.Println to log/slog JSON logs, attach request-scoped attributes with With, redact secrets using LogValuer, and change log levels at runtime.

Go
Install Go, Check Your Path, and Initialize a Module Level: Beginner

Verify your Go installation with go version and go env, initialize a module with go mod init, and fix go.mod not found errors.