How to correctly use context.Context in Go 1.7
Jack Lindamood

Thanks for the thoughtful post. I’m struggling to see how to put your chaining example at the end to practical use. The drawback I see is that the chain must effectively be re-built per request, right?

How do you see your solution mapping to http.Handlers? It seems common that the userID or any other auth state, is actually needed chiefly here. And short of building a new routing table on each request, I’m not seeing how your solution is workable.

For small, low-traffic apps, it may not be problematic to take this approach, but with dozens, hundreds, or more, endpoints that all need to implement variations of &UseUserID, it will be an unreadable mess. To say nothing of the performance hit from re-building middleware chains and routing tables for each request, rather than just once at startup.

I hope I’m just overlooking something.

Can you enlighten me?

Show your support

Clapping shows how much you appreciated Jonathan Hall’s story.