Skip to content

Go 1.22 patterns: also read a host and a trailing {$} - #1

Merged
ryoaonetsuki merged 1 commit into
ryoaonetsuki:fix/go-router-groupsfrom
SkippySteve:go-servemux-host-and-exact-match
Nov 20, 2026
Merged

ryoaonetsuki merged 1 commit into
ryoaonetsuki:fix/go-router-groupsfrom
SkippySteve:go-servemux-host-and-exact-match

Conversation

@SkippySteve

@SkippySteve SkippySteve commented Nov 20, 2026 •

Copy link
Copy Markdown

Hi! Thanks for haydenschmitty#134. While trying it on a plain net/http server I ran into two more Go 1.22 pattern shapes, so here is a small commit on top of your branch, in case it's useful:

  • A host before the path ("GET shop.example.com/api/orders", "example.com/", "api.example.com:8080/stats"): these endpoints were missed. Now the host is left out of the path and the method still comes from the pattern. A host only counts when it looks like a domain name and only on Handle/HandleFunc, so bus.Handle("devices/+/status", …) or r.Get("cdn.example.com/logo.png", …) don't become endpoints.
  • A trailing {$} (exact match): "GET /{$}" showed as GET /{$}; now it's GET /.

Example:

mux.HandleFunc("GET /{$}", home)
mux.HandleFunc("GET store.example.com/api/products/{id}", getProduct)
mux.HandleFunc("POST store.example.com/api/products", createProduct)

In a small sample (5 handlers like these, and a website calling fetch(`/api/products/${id}`), fetch('/api/products', { method: 'POST' }) and fetch('/api/reports/')), a scan found 2 routes (one of them GET /{$}) and 0 website links before, and 5 routes and 3 links after.

Changes: 3 tests in tests/go-groups.test.mjs (host and {$} cases, look-alikes, a website request reaching a host pattern), a few lines in extractGo, and half a sentence each in your CHANGELOG entry and the docs/development.md row.

Tests (node --test in node:<v>-alpine): Node 18, 20 and 22 each go from 498 tests / 496 pass / 0 fail on your branch to 501 / 499 / 0 with this. With the extract.mjs change taken out, the two new positive tests fail. claude plugin validate . passes.

Feel free to squash it into your PR, reword anything, or just take the idea.

A ServeMux pattern can name a host ("GET shop.example.com/api/orders",
"example.com:8080/"); those endpoints were missed. A host counts only when
it looks like a domain name and only on Handle/HandleFunc, so names like
"devices/+/status" or a host-like string on another router stay out.
A trailing {$} only marks an exact match, so "GET /{$}" is now GET /.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants