Sessions
Since HTTP driven applications are stateless, sessions provide a way to store information about the user across multiple requests. That user information is typically placed in a persistent store / backend that can be accessed from subsequent requests.
As soon as your Gozen app boots it automatically starts a session driver.
Setting a session
session.Set(w, r, "foo", "1")
Getting a session
b := session.Get(r, "foo")
Destroying all sessions
session.Destroy(w, r)
Passing sessions to your view/template
func ProfileView(w http.ResponseWriter, r *http.Request) { //restrict access if not logged in if session.Get(r, "loggedin") != "1" { http.Redirect(w, r, "/login", http.StatusFound) return } data := map[string]interface{}{ "name": session.Get(r, "name"), } templates.Render(w, r, "profile", data) }
Did you know?
To utilize Gozen sessions inside your controllers you must include the following import
"gozen/system/session"