Is passing user ID through context an antipattern?
Paweł Grzybek reached out after reading What belongs in Go’s context values? with a question about their auth middleware and the handler that reads the user ID from context: I validate the session in middleware, and the session record in the DB holds the user ID, which I put in the context for handlers to use later. According to your post, this is an antipattern because the handler can’t work without that value. But if I don’t use context here, I’d have to hit the sessions table again in the handler. Is this actually wrong, and if so, how do I avoid the double DB lookup? ...