Revel provides two cookie-based storage mechanisms for convenience, Session and Flash.
NOTE: To set your own cookie, use Controller.SetCookie()
Revel’s concept of session is a string map, stored as a cryptographically signed cookie.
This has some implications:
- The size limit is 4kb.
- All data must be serialized to a
string for storage.
- All data may be viewed by the user as it is not encrypted, but it is safe from modification.
The default lifetime of the session cookie is the browser lifetime. This
can be overriden to a specific amount of time by setting the session.expires
option in conf/app.conf. The format is that of
The Flash provides single-use string storage. It useful for implementing
the Post/Redirect/Get pattern,
or for transient “Operation Successful!” or “Operation Failed!” messages.
Here’s an example of that pattern:
Walking through this example:
- User fetches the settings page.
- User posts a setting (POST)
- Application processes the request, saves an error or success message to the flash, and redirects the user to the settings page (REDIRECT)
- User fetches the settings page, whose template shows the flashed message. (GET)
It uses two convenience functions:
Flash.Success(message string) is an abbreviation of
Flash.Out["success"] = message
Flash.Error(message string) is an abbreviation of
Flash.Out["error"] = message
Flash messages may be referenced by key in templates. For example, to access
the success and error messages set by the convenience functions, use these