mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Page:
Sessions flash messages
Pages
API versioning
Automatic public address
Benchmarks
Cache
Configuration
Content negotiation
Cookies
Documentation terms and conditions
Forms
Grpc
HTTP method override
HTTP referrer
Home
Host
Installation
Localization
MVC
Model validation
Our users
Project and community
Publications
Quick start
Request authentication
Response recorder
Routing context methods
Routing error handlers
Routing middleware
Routing override context
Routing path parameter types
Routing reverse lookups
Routing subdomains
Routing wrap the router
Routing
Sessions database
Sessions flash messages
Sessions
Sitemap
Starter kits
Support
Testing
URL query parameters
View
Websockets
dependency injection
2
Sessions flash messages
Gerasimos (Makis) Maropoulos edited this page 2019-10-26 18:53:48 +03:00
Table of Contents
Flash Messages
Sometimes you need to temporarily store data between requests of the same user, such as error or success messages after a form submission. The Iris sessions package supports flash messages.
As we've seen the Sessions chapter, you initialize a session like this:
import "github.com/kataras/iris/v12/sessions"
sess := sessions.New(sessions.Config{Cookie: "cookieName", ...})
// [app := iris.New...]
app.Get("/path", func(ctx iris.Context) {
session := sess.Start(ctx)
// [...]
})
The Session
contains the following methods to store, retrieve and remove flash messages.
SetFlash(key string, value interface{})
HasFlash() bool
GetFlashes() map[string]interface{}
PeekFlash(key string) interface{}
GetFlash(key string) interface{}
GetFlashString(key string) string
GetFlashStringDefault(key string, defaultValue string) string
DeleteFlash(key string)
ClearFlashes()
The method names are self-explained. For example, if you need to get a message and remove it at the next request use the GetFlash
. When you only need to retrieve but don't remove then use the PeekFlash
.
Flash messages are not stored in a database.
- What is Iris
- 📌Getting Started
- Host
- Configuration
- Routing
- HTTP Method Override
- API Versioning
- Content Negotiation
- Response Recorder
- HTTP Referrer
- Request Authentication
- URL Query Parameters
- Forms
- Model Validation
- Cache
- View
- Cookies
- Sessions
- Websockets
- Dependency Injection
- MVC
- gRPC
- Sitemap
- Localization
- Testing
- 🤓Resources
Home | Project | Quick Start | Technical Docs | Copyright © 2019-2020 Gerasimos Maropoulos. Documentation terms of use.