1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 21:45:57 +00:00

Update to 7.0.3. Read HISTORY.md

Former-commit-id: fc5a3c7ab655116ddf0dcb9c1c1657080d096c69
This commit is contained in:
kataras
2017-06-10 05:28:17 +03:00
parent dd26fbf26d
commit 6ab00aa02f
5 changed files with 48 additions and 11 deletions

View File

@@ -71,23 +71,43 @@ func (s *session) HasFlash() bool {
return len(s.flashes) > 0
}
// GetFlash returns a flash message which removed on the next request
// GetFlash returns a stored flash message based on its "key"
// which will be removed on the next request.
//
// To check for flash messages we use the HasFlash() Method
// and to obtain the flash message we use the GetFlash() Method.
// There is also a method GetFlashes() to fetch all the messages.
//
// Fetching a message deletes it from the session.
// This means that a message is meant to be displayed only on the first page served to the user
func (s *session) GetFlash(key string) (v interface{}) {
// This means that a message is meant to be displayed only on the first page served to the user.
func (s *session) GetFlash(key string) interface{} {
fv, ok := s.peekFlashMessage(key)
if !ok {
return nil
}
fv.shouldRemove = true
return fv.value
}
// PeekFlash returns a stored flash message based on its "key".
// Unlike GetFlash, this will keep the message valid for the next requests,
// until GetFlashes or GetFlash("key").
func (s *session) PeekFlash(key string) interface{} {
fv, ok := s.peekFlashMessage(key)
if !ok {
return nil
}
return fv.value
}
func (s *session) peekFlashMessage(key string) (*flashMessage, bool) {
s.mu.Lock()
if valueStorage, found := s.flashes[key]; found {
valueStorage.shouldRemove = true
v = valueStorage.value
if fv, found := s.flashes[key]; found {
return fv, true
}
s.mu.Unlock()
return
return nil, false
}
// GetString same as Get but returns as string, if nil then returns an empty string