Saving session after response?


I’m using echo-contrib/session to store some session data. As I am doing server side rendering, I want to pass my session data to the renderer, along those lines:

sess, err := session.Get("session", c)
// check err
return c.Render(http.StatusOK, "home", sess)

But here is the catch: in my template, I might call .Flashes() to display the flashes stored in the session - but calling this method is supposed to remove the flashes from the session, so I need to save the session afterwards:

err := sess.Save(c.Request(), c.Response())
// check err

Unfortunately, I’m already inside c.Render(), which is the last call before ending the handler. Is there a way to save the modified session somehow?


I would pass to the template a proper data structure instead of the session and move the logic that determines if the flashes are shown outside the template.