aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Kisiel <kamil@kamilkisiel.net>2015-08-10 07:21:15 +0300
committerKamil Kisiel <kamil@kamilkisiel.net>2015-08-10 07:21:15 +0300
commit132cb5b0eebe434c327bbf35b8373d10acd0ac4d (patch)
tree946c3159cb35aa52e7131f442b2d91a293600621
parentb49790bad8a5f6601c6feef28facd4f8e1e43ed1 (diff)
parent2c775edb25fb0f91965caac0120a59ba80858c89 (diff)
Merge pull request #40 from rcadena/save-before-write-note
Added note about calling save before writing to response.
-rw-r--r--doc.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/doc.go b/doc.go
index c5a3274..0da92a3 100644
--- a/doc.go
+++ b/doc.go
@@ -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:
@@ -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)
}