1. 16
    1. 4

      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.

      1. 2

        Seems like http.Request#Context() will get you access to framework-specific things.

      2. 1

        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.

        1. 1

          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, ...)
          
          1. 1

            You don’t even need to railroad track it if you are willing to have a longer line

        2. 1

          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”.

          1. 1

            That does seem pretty nice. I’ll have try to remember this next time I need some middleware logic.

          🇬🇧 The UK geoblock is lifted, hopefully permanently.