Would be nice to be able to add custom data to the Context to share during the request lifetime
Closed this issue · 2 comments
oleksandr commented
This could be a good example:
http://www.gorillatoolkit.org/pkg/context
Thus in the request handling chain (Before -> Controller's Method -> After) it would be really easy to share the data.
As an example we use:
- Before: parse Authorization header, extract Token if available, fetch the corresponding user/session data, assign to context such as context.Set(CURRENT_USER_KEY, userStructure)
- Controller's method just performs the check context.Get(CURRENT_USER_KEY) != nil
This would help to avoid duplication of code especially related to authentication...
oleksandr commented
It seems that is already possible with c.Data().Set/Get, right?
matryer commented
Right, the context.Data
thing is exactly for that. Goweb ignores the Data
object.
It's an objects.Map
from the http://godoc.org/github.com/stretchr/stew/objects package.