Getting Started with Go Basics
Go Basics is a collection of in-depth articles on Go internals, concurrency, the standard library, and best practices. Each article goes beyond surface-level explanations — you'll find runtime mechanics, Mermaid diagrams, and interactive code examples you can run directly in the browser.
package main
import "fmt"
func main() {
fmt.Println("Hello from Go Basics!")
}
What's Covered
Functions
Variadic parameters, closures, and the mechanics of function values.
| Article | What you'll learn |
|---|---|
| Variadic Functions | How ...T works, slice aliasing, forwarding patterns |
| Closures | Variable capture by reference, loop capture bug, memoization |
Concurrency
The full stack: scheduler, channels, synchronization primitives, and real-world patterns.
| Article | What you'll learn |
|---|---|
| Concurrency vs. Parallelism | The precise distinction, I/O-bound vs CPU-bound, GOMAXPROCS |
| Goroutine Scheduling | G/M/P model, work stealing, syscall handoff |
| Goroutine Preemption | Why tight CPU loops can starve other goroutines |
| Go Memory Model | Happens-before, sequentially consistent atomics |
| Happens-Before | Mutex, channels, atomics, WaitGroup guarantees |
| Data Races | Why "it works on my machine" is a lie |
| Race Detector | What it catches and what it can't prove |
| Channel Internals | Buffered vs unbuffered, blocking semantics, hchan layout |
| select Behavior | Fairness, pseudo-random case picking |
| Closing Channels | Who closes, what receivers observe |
| Nil Channels | The disabled-case pattern |
| Context Cancellation | Deadlines, propagation, cleanup patterns |
| Concurrency Patterns | Pipeline, fan-out, fan-in, done channel |
| sync.WaitGroup | Add/Done/Wait rules, copy gotcha, error collection |
| sync.Once | Internals, common deadlock patterns |
| sync.Pool | What it is, what it isn't, GC interaction |
| atomic vs Mutex vs Channels | Decision guide for synchronization |
| GOMAXPROCS | What it really controls |
| Map Concurrency | Why concurrent writes crash Go |
| Goroutine Leaks | Causes, detection with pprof and goleak, prevention |
| errgroup | Concurrent tasks with error propagation and cancellation |
Internals
How the Go runtime and compiler work under the hood.
| Article | What you'll learn |
|---|---|
| Packages and Modules | Package vs module, visibility rules, init, blank imports |
| Pointers | Value vs pointer semantics, nil, escape analysis, no arithmetic |
| Memory Management | Stack vs heap, TCMalloc allocator, escape triggers |
| Escape Analysis | Stack vs heap allocation, reading -gcflags="-m" output |
| Slice Internals | len/cap, append growth, shared backing arrays |
| Map Internals | Hashing, buckets, growth, iteration randomness |
| String Immutability | string/[]byte conversions and allocations |
| defer Internals | Stack, argument evaluation, hot loop cost |
| GC Basics | Tri-color marking, STW phases |
| Write Barrier | Why it exists, performance impact |
| Memory Alignment | False sharing in structs |
| init() Order | Package init sequence and traps |
Type System
Interfaces, generics, embedding, and the type machinery beneath them.
| Article | What you'll learn |
|---|---|
| Interfaces Under the Hood | itab, dynamic type, dynamic value |
| Empty Interface | any, type assertions, cost |
| Value vs Pointer Receivers | Method sets, interface satisfaction |
| Embedding | Promotion, ambiguity, zero values |
| Generics | Type parameters, constraints, instantiation |
Error Handling
Idiomatic error patterns, panic mechanics, and clean shutdown.
| Article | What you'll learn |
|---|---|
| Error Handling Patterns | Wrapping, errors.Is/As, sentinel errors |
| panic and recover | Rules, goroutine boundaries, server recovery pattern |
| Graceful Shutdown | OS signals, context cancellation, draining workers |
Testing
Table-driven tests, benchmarks, and Go's testing idioms.
| Article | What you'll learn |
|---|---|
| Table-Driven Tests | t.Run, subtests, benchmarks, t.Helper, coverage |
Standard Library
The I/O model, HTTP internals, JSON pitfalls, and timers.
| Article | What you'll learn |
|---|---|
| io.Reader and io.Writer | Composition model, io.Copy, bufio, HTTP bodies |
| time.Timer and time.Ticker | Stop/Reset pitfalls, time.After leaks, ticker drops |
| net/http Transport | Keep-alive, connection pooling, timeouts |
| http.Client Reuse | Why per-request clients are a bug |
| JSON Encoding Pitfalls | Numbers, interface{}, allocations |
Tooling
Profiling, build system, and the C boundary.
| Article | What you'll learn |
|---|---|
| pprof Basics | CPU, heap, goroutine, mutex profiling |
| Build Tags | Why builds can silently change |
| cgo Overhead | Why crossing the C boundary is expensive |
How to Read This Site
Articles are self-contained — you can read in any order. That said, some natural reading paths:
- Concurrency deep dive
- Performance & internals
- Production readiness
- Goroutine Scheduling — understand the G/M/P model first
- Concurrency vs. Parallelism — clear up the fundamental distinction
- Channel Internals — how channels are implemented
- Go Memory Model + Happens-Before — the formal rules
- Data Races + Race Detector — how to find bugs
- Concurrency Patterns — pipeline, fan-out, fan-in
- Goroutine Leaks — production survival
- Escape Analysis — stack vs heap
- Memory Management — the allocator
- GC Basics + Write Barrier — GC mechanics
- Memory Alignment — struct layout and false sharing
- sync.Pool — reducing allocator pressure
- pprof Basics — profiling in practice
- Error Handling Patterns — idiomatic errors
- Context Cancellation — deadlines and propagation
- Graceful Shutdown — clean process lifecycle
- Goroutine Leaks — how to detect and prevent them
- http.Client Reuse — connection pool hygiene
- errgroup — concurrent work with error propagation
- Table-Driven Tests — testing idioms