These are chat archives for gin-gonic/gin

Jun 2015
Lorenzo Landolfi
Jun 25 2015 12:04
@MrSpock c.Set("key", value) ; val, bool := c.Get("key).
I don't know if you want to set values outside the handler. I think that it is impossible if you don't want to write a middleware.
Lorenzo Landolfi
Jun 25 2015 12:12
1) You could do another route with the same middleware/handler or a new handler and use redirect(if you have to handle multiple routes, but I don't see where to apply this irl)
2) I think that there aren't regex in httprouter yet(or never maybe). That's one of the reasons that makes it so fast!
Marcin Jurczuk
Jun 25 2015 13:07
Yes. It looks like I have to write som middleware since. Thx
Jamie Stackhouse
Jun 25 2015 13:19

Yea @MrSpock, the only place you get access to the gin.Context is inside a gin.HandlerFunc.. after that you can pass it wherever you want though.

So if you want to setup templates etc, a middleware would be a good place to do that for your app.
If you want to populate it with authentication information or some such, again, middleware.

I do find that writing small helper functions to retrieve the data is very helpful.

Things like..

func MustGetUserId(c *gin.Context) string { return c.MustGet(middleware.UserKey).(string) }
Getting it back into the type as quick as possible has been great.
David Martorana
Jun 25 2015 16:21
It's been a while since I've updated Gin - but it looks like httprouter is no longer used?
David Martorana
Jun 25 2015 16:37
Oh, look at that. Search. Found the answer :)