在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Revel提供两个基于cookie的存储机制. // A signed cookie (and thus limited to 4kb in size). // Restriction: Keys may not have a colon in them. type Session map[string]string // Flash represents a cookie that gets overwritten on each request. // It allows data to be stored across one page at a time. // This is commonly used to implement success or error messages. // e.g. the Post/Redirect/Get pattern: http://en.wikipedia.org/wiki/Post/Redirect/Get type Flash struct { Data, Out map[string]string } SessionRevel session是一个字符串字典, 存储为加密签名的cookie. 它有下面的暗示:
FlashFlash提供一个单次使用的字符串存储. 它对于实现the Post/Redirect/Get 模式很有帮助,或者用于转换"操作成功!"或"操作失败!"消息. 下面是这个模式的例子: // Show the Settings form func (c App) ShowSettings() rev.Result { return c.Render() } // Process a post func (c App) SaveSettings(setting string) rev.Result { c.Validation.Required(setting) if c.Validation.HasErrors() { c.Flash.Error("Settings invalid!") c.Validation.Keep() c.Params.Flash() return c.Redirect(App.ShowSettings) } saveSetting(setting) c.Flash.Success("Settings saved!") return c.Redirect(App.ShowSettings) } 我们来看一下这个例子:
它使用两个方便的函数:
至此完成. |
请发表评论