A real server answers different paths differently. Today you build a router that maps a method and path to a handler, so "/" and "/about" return different pages.
Register handlers keyed by method and path, and dispatch a request to the matching one.
A server that returns the same body for every path is not much of a server. A
router (often called a mux) fixes that: it holds a table of registered routes
and picks the Handler whose method and path match the request. Handlers take a
Request and return a Response — the two types the chapters built.
Key the table on both method and path from the very start, even though you
only register GET routes today. It costs nothing now and means the next lessons
— a 404 for unknown paths, a 405 for the wrong method — slot in without reworking
the table’s shape.
type Handler func(Request) Responsetype Mux struct{ routes map[string]Handler }func key(method, path string) string { return method + " " + path }func (m *Mux) Handle(method, path string, h Handler) { m.routes[key(method, path)] = h }func (m *Mux) dispatch(r Request) Response { return m.routes[key(r.Method, r.Path)](r) }