Go's standard library ships its own HTTP server, and ServeMux is its router. Every request to a Go server that uses http.HandleFunc arrives here. Go 1.22 added method and wildcard patterns, and this method still keeps the old matcher available behind a setting.
What to look for
The special case first: a request for "*" is refused with Bad Request before any routing happens.
How much Thunder could read
9 of 10 steps put into words; the other 1 is shown as code.
Read by the current Thunder compiler when this page was built. Hand-checked against the code: accurate, with some wording that is thin or close to the code.
››››
Flow: How does it go? One action or rule as a path: questions with Yes and No, repeats, the Stops, what happens if something goes wrong, and what always happens at the end.
Serve mux can
Serve http
From codelines 2669–2683
Author's noteServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.
Is the r's request uri "*"?
Yes
R.ProtoAtLeast(1, 1)?
Yes
w.Header().Set("Connection", "close")
No ↓ continue
→Does: Calls write header
Stops here
No ↓ continue
=Works out: Declares h
Is use121 set?
Yes
=Works out: Works out h from find handler
No
=Works out: Works out h, the r's pat, the r's matches from find handler
The same reading as Thunder Text, built with this page
Serve http (Serve mux)
Author's note: ServeHTTP dispatches the request to the handler whose pattern most closely matches the request URL.
- Ask: Is the r's request uri "*"? (line 2670)
Yes:
- Ask: R.ProtoAtLeast(1, 1)? (line 2671)
Yes:
- `w.Header().Set("Connection", "close")` (code, not explained) (line 2672)
No: continue
- Calls write header (line 2674)
- Stops here (line 2675)
No: continue
- Declares h (line 2677)
- Ask: Is use121 set? (line 2678)
Yes:
- Works out h from find handler (line 2679)
No:
- Works out h, the r's pat, the r's matches from find handler (line 2681)
- Calls serve http (line 2683)
Copyright (c) 2009 The Go Authors. All rights reserved.. Licensed under the BSD 3-Clause. The code is shown unmodified; the Thunder reading is ThunderLang's.
Full license text (LICENSE)
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.