1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-02 13:00:17 +00:00

add api comments in file config.go, controller.go, filter.go and flash.go

This commit is contained in:
傅小黑
2013-12-20 21:16:26 +08:00
parent 933e98e4f2
commit b459cf2347
4 changed files with 126 additions and 31 deletions

View File

@ -6,18 +6,22 @@ import (
"strings"
)
// the separation string when encoding flash data.
const BEEGO_FLASH_SEP = "#BEEGOFLASH#"
// FlashData is a tools to maintain data when using across request.
type FlashData struct {
Data map[string]string
}
// NewFlash return a new empty FlashData struct.
func NewFlash() *FlashData {
return &FlashData{
Data: make(map[string]string),
}
}
// Notice writes notice message to flash.
func (fd *FlashData) Notice(msg string, args ...interface{}) {
if len(args) == 0 {
fd.Data["notice"] = msg
@ -26,6 +30,7 @@ func (fd *FlashData) Notice(msg string, args ...interface{}) {
}
}
// Warning writes warning message to flash.
func (fd *FlashData) Warning(msg string, args ...interface{}) {
if len(args) == 0 {
fd.Data["warning"] = msg
@ -34,6 +39,7 @@ func (fd *FlashData) Warning(msg string, args ...interface{}) {
}
}
// Error writes error message to flash.
func (fd *FlashData) Error(msg string, args ...interface{}) {
if len(args) == 0 {
fd.Data["error"] = msg
@ -42,6 +48,8 @@ func (fd *FlashData) Error(msg string, args ...interface{}) {
}
}
// Store does the saving operation of flash data.
// the data are encoded and saved in cookie.
func (fd *FlashData) Store(c *Controller) {
c.Data["flash"] = fd.Data
var flashValue string
@ -51,6 +59,7 @@ func (fd *FlashData) Store(c *Controller) {
c.Ctx.SetCookie("BEEGO_FLASH", url.QueryEscape(flashValue), 0, "/")
}
// ReadFromRequest parsed flash data from encoded values in cookie.
func ReadFromRequest(c *Controller) *FlashData {
flash := &FlashData{
Data: make(map[string]string),