Hi, I have a situation where I have a chain of middlewares with a logger middleware that comes before an authentication middleware. Logger middleware logs about the incoming request, calls the next middleware in the chain and then logs about the response. Authentication middleware authenticates the incoming request and adds the authenticated user to the request context (which ends up creating a new request object to be passed downstream) before invoking the next middleware.
Problem statement is that I want to log the authenticated user id in the logger middleware. But because the request object known to the logger middleware is not the same request object that the authentication middleware set the user context with, I do not have the user information available in the logger middleware. I am deliberating on the ways of achieving this. Right now, I am contemplating to add a pointer to a zero value struct with agreed upon attributes (or with just a context attribute) or a map to the context of the request object in logger middleware or an earlier middleware. Then, in any downstream middleware I can set values of struct attributes (or manipulate the context attribute) or set key value pairs to the map. This makes the "context" being set by downstream middlewares available to upstream middlewares after a downstream middleware returns. Are there better ways of doing it? Hopefully, others in the community may have also faced similar problems and I would like to know about any alternate ways that others may have used. Thanks, Anuj -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CABnk5p0H0YUm2vkL9Nb_CXVpgRy%2BJ87O6NH8FmgR5ewL4%3DSnsg%40mail.gmail.com.