Skip to content

Commit

Permalink
Merge pull request gorilla#40 from rcadena/save-before-write-note
Browse files Browse the repository at this point in the history
Added note about calling save before writing to response.
  • Loading branch information
kisielk committed Aug 10, 2015
2 parents b49790b + 2c775ed commit 132cb5b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ And finally we call session.Save() to save the session in the response.
Note that in production code, we should check for errors when calling
session.Save(r, w), and either display an error message or otherwise handle it.
Save must be called before writing to the response, otherwise the session
cookie will not be sent to the client.
Important Note: If you aren't using gorilla/mux, you need to wrap your handlers
with context.ClearHandler as or else you will leak memory! An easy way to do this
is to wrap the top-level mux when calling http.ListenAndServe:
Expand All @@ -79,12 +82,10 @@ flashes, call session.Flashes(). Here is an example:
// Get the previously flashes, if any.
if flashes := session.Flashes(); len(flashes) > 0 {
// Just print the flash values.
fmt.Fprint(w, "%v", flashes)
// Use the flash values.
} else {
// Set a new flash.
session.AddFlash("Hello, flash messages world!")
fmt.Fprint(w, "No flashes found.")
}
session.Save(r, w)
}
Expand Down

0 comments on commit 132cb5b

Please sign in to comment.