func main() { m := martini.Classic() // Initializing session store store := sessions.NewCookieStore([]byte("secret123")) m.Use(sessions.Sessions("my_session", store)) m.Get("/", func(session sessions.Session) string { session.Set("username", "John") return "Session created. Go to /user to see the session value." }) m.Get("/user", func(session sessions.Session) string { username := session.Get("username") return "Hello, " + username.(string) }) m.Run() }
func main() { m := martini.Classic() // Initializing session store store := sessions.NewCookieStore([]byte("secret123")) m.Use(sessions.Sessions("my_session", store)) m.Get("/logout", func(session sessions.Session) string { session.Clear() return "You have been logged out." }) m.Run() }This example demonstrates how to delete a session by clearing all its values.