julienschmidt/httprouter ? reverse-engineered prompt

Reverse engineered prompt

Build me a small Go HTTP router library like HttpRouter that’s fast and simple to use.

I want it to match routes exactly, support request methods, named path params like /hello/:name, and catch all paths like /src/*filepath. It should automatically handle trailing slash redirects, clean up bad paths like double slashes or ../, and optionally do case insensitive lookups. Please include custom NotFound, MethodNotAllowed, OPTIONS handling, and a panic recovery handler so the server doesn’t crash. It should also support serving static files.

The main goal is performance, so keep allocations very low and use a compact tree based matcher under the hood. Make the public API feel natural for Go, with simple handler registration and a clear way to read params from the request or handler arguments. Add a few examples and tests that show normal routing, params, redirects, and error cases. If you need to check current Go docs or best practices, look them up online.

Are you gonna build this?

make sure you review the code using coderabbit

Try freeSponsored — opens CodeRabbit in a new tab