In particular, these started failing when running tests under the race
detector in Go 1.4 [0], probably due to some kind of (GC?) hijinks
clearing out the sync.Pool.
[0]: these tests might have also failed in 1.3, but I didn't check
"util" is a really bad name for a package since it isn't very
descriptive and so often collides with other names.
Unfortunately, this is a breaking change, but it's both very easy to fix
and perhaps more importantly also better to do now than later.
This is pretty frustrating: it doesn't look like it's going to be easy
to get the "cover" tool to work across both 1.3 and 1.4, since they
aren't able to agree on where to install the tool from. I'm sure there's
a way to work around this, but in the meantime let's just disable
coverage testing entirely.
Previously, a route like "/:a.png" would match "/foo/bar/baz.png".
This was incorrect, as all matches should be restricted to path segments
(or smaller, as dictated by a break character).
This bug was introduced in 1a390aba1c.
Fixes#75.
This middleware makes it much easier to write sub-routes, allowing you
to make the sub-router ignorant of its parent router's matched prefix.
The example app has also been modified to use this functionality for its
admin pages.
Fixes#65.
This is a breaking API change that changes how wildcard patterns are
treated. In particular, wildcards are no longer allowed to appear at
arbitrary places in the URL, and are only allowed to appear immediately
after a path separator. This change effectively changes the wildcard
sigil from "*" to "/*".
Users who use wildcard routes like "/hello*" will have to switch to
regular expression based routes to preserve the old semantics.
The motivation for this change is that it allows the router to publish a
special "tail" key which represents the unmatched portion of the URL.
This is placed into URLParams under the key "*", and includes a leading
"/" to make it easier to write sub-routers.
This allows you to match "/a/cat.gif" with patterns like "/a/:b.:c".
Thanks to @Minecrell for an early patch implementing this functionality.
Fixes#75.
Fixes#48.
Make the bytecode runner return the route that we're going to use. It's
up to the router itself to dispatch to that route.
Besides feeling a teensy bit cleaner, this refactoring is to prepare for
a "Router" middleware, which will allow application developers to
control when in the middleware stack routing occurs.
I originally exposed Compile() for exactly this use case, but apparently
I never actually implemented this. Oops.
In any event, this makes the first request a little faster (an extremely
unscientific test suggests on the order of 10 microseconds). Also, if
something goes terribly wrong during route compilation, it would fail
before we start listening on the socket.
Instead of using struct embedding to build web.Mux, start moving towards
explicit mappings. This doesn't actually change the public API of
web.Mux, but feels a little cleaner to me.
The longer-term thing here is to get rid of the functions defined on
Muxes in the public documentation that are defined on "rt *Mux", which
is just plain ugly.
This is meant to accomplish a few things:
1. graceful no longer spawns an additional goroutine per connection.
Instead, it maintains a sharded set of idle connections that a single
reaper goroutine can go through when necessary.
2. graceful's connection struct has a more orthogonal set of connection
state flags, replacing the harder-to-understand state machine. The
underlying mechanics are largely the same, however.
3. graceful now uses the Go 1.3 ConnState API to avoid the "200-year
SetReadDeadline hack." It still falls back on SetReadDeadline on Go
1.2 or where ConnState does not apply.
This feature can be used in place of the pile of hacks in middleware.go,
and doesn't involve awkwardly shimming out a http.ResponseWriter. Sounds
like a win-win!
It turns out WriterProxy is pretty generally useful, especially when
defining custom http loggers. Expose it in a util package so that other
packages can use it.