summaryrefslogtreecommitdiff
path: root/doc.go
diff options
context:
space:
mode:
authorrcadena <robert.cadena@gmail.com>2015-02-11 20:37:20 +0300
committerrcadena <robert.cadena@gmail.com>2015-02-11 20:37:20 +0300
commit0f44a27391116bbb840afe7ee861d0f0d0302a1b (patch)
tree628ddd1b386af1c3ccb8a0cd7191a209964e499b /doc.go
parent13c86220d944600e7a6e3de6c87418896ccfbe77 (diff)
Added note about calling save before writing to response.
Also removed calls to fmt.Fprintf in AddFlash example. If a user follows the old example then the session won't be stored. See: https://github.com/gorilla/sessions/issues/39
Diffstat (limited to 'doc.go')
-rw-r--r--doc.go7
1 files changed, 4 insertions, 3 deletions
diff --git a/doc.go b/doc.go
index 7f8be22..c4012af 100644
--- a/doc.go
+++ b/doc.go
@@ -56,6 +56,9 @@ is to wrap the top-level mux when calling http.ListenAndServe:
The ClearHandler function is provided by the gorilla/context package.
+Also: Call Save before writing to the response, otherwise the session
+cookie will not be sent to the client.
+
That's all you need to know for the basic usage. Let's take a look at other
options, starting with flash messages.
@@ -69,12 +72,10 @@ flashes, call session.Flashes(). Here is an example:
session, _ := store.Get(r, "session-name")
// 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)
}