Almost always middleware require a logger, database connection and other service.
I’ve read this article and dont understand how it is differ from a plain (with gorrila toolkit or plain net/http) middleware implementations.
This is just another piece of overengeenering.
Seems like http.Request#Context() will get you access to framework-specific things.
I’m surprised they didn’t proofread this before hitting publish. The plural of middleware is still just middleware. It’s like water. You would not say “a water”.
That does seem pretty nice. I’ll have try to remember this next time I need some middleware logic.
I always reach for alice if I have to do any chaining of middleware functions. I like this library because it allows you to use any middleware out there so long as it is an http.Handler.
Why bring a dependency into your project for a single convenience function that isn’t actually more convenient than typing things out explicitly?
var h http.Handler
h = actualHandler
h = innermostMiddleware(h, ...)
h = additionalMiddleware(h, ...)
h = outermostMiddleware(h, ...)
You don’t even need to railroad track it if you are willing to have a longer line