Flash
package revel
type Flash struct {
Data, Out map[string]string
}
func (f Flash) Error(msg string, args ...interface{}) {
if len(args) == 0 {
f.Out["error"] = msg
} else {
f.Out["error"] = fmt.Sprintf(msg, args...)
}
}
func (f Flash) Success(msg string, args ...interface{}) {
if len(args) == 0 {
f.Out["success"] = msg
} else {
f.Out["success"] = fmt.Sprintf(msg, args...)
}
}
func FlashFilter(c *Controller, fc []Filter) {
c.Flash = restoreFlash(c.Request.Request)
c.RenderArgs["flash"] = c.Flash.Data
fc[0](c, fc[1:])
var flashValue string
for key, value := range c.Flash.Out {
flashValue += "\x00" + key + ":" + value + "\x00"
}
c.SetCookie(&http.Cookie{
Name: CookiePrefix + "_FLASH",
Value: url.QueryEscape(flashValue),
HttpOnly: CookieHttpOnly,
Secure: CookieSecure,
Path: "/",
})
}