Closed iambudi closed 5 years ago
1.)
You could, for example, store the user ID in your session when a user logs in.
ctx.Session().Set("userID", 123)
On the event handler, restore the user ID from the session cookie:
ctx.Session().Get("userID")
I usually write a wrapper function around this and call it GetUser(ctx)
.
2.)
Another method would be to create your own Context
type...
type MyContext struct {
aero.Context
UserID string
}
and then pass your modified context to the next(ctx)
call in the middleware. That way, all contexts will include a UserID field after casting the type.
I prefer the first method because it avoids an allocation, but the second method is also perfectly fine.
Please let me know if anything is unclear, otherwise I'll keep this as closed now.
Is there any best practice in aero to handle SSE for specific client only?