Skip to main content

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.

ArticleWhat you'll learn
Variadic FunctionsHow ...T works, slice aliasing, forwarding patterns
ClosuresVariable capture by reference, loop capture bug, memoization

Concurrency

The full stack: scheduler, channels, synchronization primitives, and real-world patterns.

ArticleWhat you'll learn
Concurrency vs. ParallelismThe precise distinction, I/O-bound vs CPU-bound, GOMAXPROCS
Goroutine SchedulingG/M/P model, work stealing, syscall handoff
Goroutine PreemptionWhy tight CPU loops can starve other goroutines
Go Memory ModelHappens-before, sequentially consistent atomics
Happens-BeforeMutex, channels, atomics, WaitGroup guarantees
Data RacesWhy "it works on my machine" is a lie
Race DetectorWhat it catches and what it can't prove
Channel InternalsBuffered vs unbuffered, blocking semantics, hchan layout
select BehaviorFairness, pseudo-random case picking
Closing ChannelsWho closes, what receivers observe
Nil ChannelsThe disabled-case pattern
Context CancellationDeadlines, propagation, cleanup patterns
Concurrency PatternsPipeline, fan-out, fan-in, done channel
sync.WaitGroupAdd/Done/Wait rules, copy gotcha, error collection
sync.OnceInternals, common deadlock patterns
sync.PoolWhat it is, what it isn't, GC interaction
atomic vs Mutex vs ChannelsDecision guide for synchronization
GOMAXPROCSWhat it really controls
Map ConcurrencyWhy concurrent writes crash Go
Goroutine LeaksCauses, detection with pprof and goleak, prevention
errgroupConcurrent tasks with error propagation and cancellation

Internals

How the Go runtime and compiler work under the hood.

ArticleWhat you'll learn
Packages and ModulesPackage vs module, visibility rules, init, blank imports
PointersValue vs pointer semantics, nil, escape analysis, no arithmetic
Memory ManagementStack vs heap, TCMalloc allocator, escape triggers
Escape AnalysisStack vs heap allocation, reading -gcflags="-m" output
Slice Internalslen/cap, append growth, shared backing arrays
Map InternalsHashing, buckets, growth, iteration randomness
String Immutabilitystring/[]byte conversions and allocations
defer InternalsStack, argument evaluation, hot loop cost
GC BasicsTri-color marking, STW phases
Write BarrierWhy it exists, performance impact
Memory AlignmentFalse sharing in structs
init() OrderPackage init sequence and traps

Type System

Interfaces, generics, embedding, and the type machinery beneath them.

ArticleWhat you'll learn
Interfaces Under the Hooditab, dynamic type, dynamic value
Empty Interfaceany, type assertions, cost
Value vs Pointer ReceiversMethod sets, interface satisfaction
EmbeddingPromotion, ambiguity, zero values
GenericsType parameters, constraints, instantiation

Error Handling

Idiomatic error patterns, panic mechanics, and clean shutdown.

ArticleWhat you'll learn
Error Handling PatternsWrapping, errors.Is/As, sentinel errors
panic and recoverRules, goroutine boundaries, server recovery pattern
Graceful ShutdownOS signals, context cancellation, draining workers

Testing

Table-driven tests, benchmarks, and Go's testing idioms.

ArticleWhat you'll learn
Table-Driven Testst.Run, subtests, benchmarks, t.Helper, coverage

Standard Library

The I/O model, HTTP internals, JSON pitfalls, and timers.

ArticleWhat you'll learn
io.Reader and io.WriterComposition model, io.Copy, bufio, HTTP bodies
time.Timer and time.TickerStop/Reset pitfalls, time.After leaks, ticker drops
net/http TransportKeep-alive, connection pooling, timeouts
http.Client ReuseWhy per-request clients are a bug
JSON Encoding PitfallsNumbers, interface{}, allocations

Tooling

Profiling, build system, and the C boundary.

ArticleWhat you'll learn
pprof BasicsCPU, heap, goroutine, mutex profiling
Build TagsWhy builds can silently change
cgo OverheadWhy 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:

  1. Goroutine Scheduling — understand the G/M/P model first
  2. Concurrency vs. Parallelism — clear up the fundamental distinction
  3. Channel Internals — how channels are implemented
  4. Go Memory Model + Happens-Before — the formal rules
  5. Data Races + Race Detector — how to find bugs
  6. Concurrency Patterns — pipeline, fan-out, fan-in
  7. Goroutine Leaks — production survival