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
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.

Go
Strings, Bytes, and Runes in Go: Why len() Counts Bytes Level: Beginner

See why len() counts UTF-8 bytes instead of characters, iterate safely over runes with range, and slice UTF-8 text without splitting multi-byte characters.

Go
Value vs. Pointer Receivers in Go: Why Method Changes Disappear Level: Beginner

Reproduce lost struct mutations with value receivers, switch to pointer receivers cleanly, and keep receiver types consistent across a struct.

Go
Wrap and Check Errors in Go With fmt.Errorf("%w") and errors.Is Level: Beginner

Add context to Go errors using fmt.Errorf("%w"), inspect wrapped chains with errors.Is and errors.As, and avoid breaking checks with == or %v.

Go
Write Table-Driven Unit Tests in Go With testing.T and t.Run Level: Beginner

Structure Go unit tests as a slice of cases, run named subtests with t.Run, and choose between t.Fatalf and t.Errorf.

Go
Understand Go Pointers (& and *) Without Guessing Level: Beginner

Learn how &x and *p work in Go, why value parameters copy data, and how to guard against nil pointer dereferences. After this, pointer bugs stop being guesswork.

Go
Organize Go Modules With go mod tidy and internal/ Packages Level: Beginner

Structure a multi-package Go repository with cmd/, internal/, go get, and go mod tidy. After this, private packages cannot be imported from outside your module.