forked from hoisie/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash.go
More file actions
40 lines (32 loc) · 704 Bytes
/
flash.go
File metadata and controls
40 lines (32 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package web
type Flash struct {
Alert string
Notice string
}
var FlashAlertKey string = "ZQFA"
var FlashNoticeKey string = "ZQFN"
func (ctx *Context) SetFlashAlert(msg string) {
ctx.SetSecureCookie(FlashAlertKey, msg, 60)
return
}
func (ctx *Context) SetFlashNotice(msg string) {
ctx.SetSecureCookie(FlashNoticeKey, msg, 60)
return
}
func (ctx *Context) GetFlash() *Flash {
if ctx.flash != nil {
return ctx.flash
}
flash := &Flash{}
var ok bool
flash.Alert, ok = ctx.GetSecureCookie(FlashAlertKey)
if ok {
ctx.RemoveCookie(FlashAlertKey)
}
flash.Notice, ok = ctx.GetSecureCookie(FlashNoticeKey)
if ok {
ctx.RemoveCookie(FlashNoticeKey)
}
ctx.flash = flash
return flash
}