package main wraps the mux. The mux calls Handler. Handler may go a worker. The contract — types, slices, errors — links into Handler. Pan down: concurrency catalog, then the scheduler as a pipeline, with the traps crossed out. Click Handler, Accept, or nil interface.
Click a shape or a question
Questions this tree answers
A request · one G per accept · cancel is not optional
Types · slices · errors
types · pointers
slices · maps
errors · defer · modules
main → mux → handler
Operation
Library
Receivers · interfaces
GMP · one G per request
Goroutine stack
Heap / escape
Slice header
Interface word
GC / reachability
Concurrency catalog
go · bound
channels · select
context · sync
generics · io
Scheduler — pipeline and traps
G created → drain
don’t · advanced last
ientrypackage main · func main
runtime dials after init
irejectedclass extends Server
is-a · not the model
don’t subclass
irouterServeMux
patterns · two children
Handler + library · not nested
ioperationServeHTTP
decode · save · write
one G for this request
iwriteWriteHeader
status then body
no extra G
iside pathgo fanout
after commit
must watch ctx
ilibraryinvoice.Save
domain · not main
tests import this
sibling of Handler, not a child
iruntimeruntime calls main()
after init
you do not dial
iwrongmain() yourself
not importable
tests call the library
izero0 · false · "" · nil
declared is valid
nil map write panics
ideclarevar x T · x := v
:= needs a new name
inner err shadows
iaddress*T · &x
share vs copy
nil deref panics
iallocmake vs new
make: slice/map/chan
new: *zero
irecordtype Invoice struct
keyed literal
copy on assign
methods hang off this
iheaderslice { ptr, len, cap }
array is elsewhere
reslice aliases
igrowa = append(a, x)
take the return
alias until realloc
ivalue[N]T copies
N is in the type
API wants a slice
ihashmake(map[K]V)
nil write panics
no concurrent write
ibytesstring · rune · byte
len is bytes
range is runes
immutable
ireturns(T, error)
error last
closures share the var
iLIFOdefer cancel()
args now · call later
not per-iteration
ivalueif err != nil
not an exception
visible path
ichainfmt.Errorf("%w")
Is / As walk
%v severs
iimpossiblepanic / recover
not HTTP 400
recover in defer
iAPIExport = capital
directory is package
init is a trap
itableTestFoo(t *testing.T)
t.Run · -race
import the library
iidentitygo.mod
path is the name
go.sum · /v2 is a new module
ipointer recvfunc (c *Cart) Add
mutates same Cart
one method set
ivalue recvfunc (c Cart) Total
copy · mutation dies
keep * if any method needs *
ihas-aembed http.Handler
promotion, not is-a
icontracttype Store interface
implicit · keep it small
itraperr = (*T)(nil)
itab set · not nil
inarrowv, ok := x.(T)
errors.As on wraps
iGG · goroutine
stack · parked or running
not an OS thread
iMM · OS thread
must hold a P to run Go
syscall may stick the M
iPP · processor
holds the runqueue
GOMAXPROCS is not a G cap
istackServeHTTP frame
locals die on return
unless they escape
cheap path
iheap*Invoice escaped
address needed later
go build -gcflags=-m
GC work
iheaderbody { ptr, len, cap }
three words on the stack
array on the heap
reslice aliases
itwo wordserror { itab, data }
dynamic type + value
nil trap = itab set
indirect call
ieligibleunreachable → GC
no path from roots
parked G still roots
imeasurepprof heap · goroutine
names the live set
don’t guess GOGC
istartgo f()
new G · small stack
must be able to end
iboundworker pool
SetLimit
ceiling around Gs
ijoinAdd · go · Wait
Add before go
defer Done
igrouperrgroup
first error
cancels siblings
WaitGroup + ctx
imeetmake(chan T)
send waits for receive
happens-before
islackmake(chan T, n)
full = backpressure
huge n = leak
iendclose(ch) · range
sender closes
double close panics
iwaitselect { Done }
random among ready
always ctx.Done
iproverbShare by communicating
pass ownership on a chan
mutex if already shared
ifirst argctx context.Context
deadline · cancel
don’t store on the server
ilockmu.Lock()
defer Unlock
don’t copy · hold short
iwordatomic.Int64
one word
not two fields
ioncesync.Once
init, not per request
panic counts as done
itype paramfunc Max[T cmp.Ordered]
constraints are interfaces
not a one-type wrapper
compile time
ibytesio.Reader · Writer
Read([]byte)
compose wrappers
Copy · LimitReader
EOF is done
i1 createNew G
go f() · small stack
i2 runqueueP local runqueue
ready Gs
i3 executeM runs the G
ServeHTTP here
i4 syscallSyscall · P stolen
netpoll parks G
i5 stealWork steal
idle P takes half
does not split a tight loop
i6 preemptPreempt the G
fairness · lock still held
iparkPark on chan / select
off the runqueue
must wake · ctx.Done
idrainShutdown(ctx)
stop accept · budget
no naked Exit
imapG ≈ goroutine · M ≈ thread · P ≈ runqueue
create → runqueue → execute → park → drain
GOMAXPROCS caps Ps, not Gs
iforbiddengo in a million loop
no ceiling
pool instead
iforbiddenWithCancel without defer
leaks the child
timer may linger
iundefinedtwo Gs · one word · no sync
go test -race
map concurrent write panics
iescape hatchunsafe.Pointer
uintptr is not a pointer
almost never in Handler
iruntime typesreflect.Type · Value
json lives here
not the hot loop
72%
Click a box · three arrows off a layer are what it allows