本文整理匯總了Golang中github.com/revel/revel.Controller.SetCookie方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.SetCookie方法的具體用法?Golang Controller.SetCookie怎麽用?Golang Controller.SetCookie使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/revel/revel.Controller
的用法示例。
在下文中一共展示了Controller.SetCookie方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SessionFilter
// SessionFilter is a Revel Filter that retrieves and sets the session cookie.
// Within Revel, it is available as a Session attribute on Controller instances.
// The name of the Session cookie is set as CookiePrefix + "_SESSION".
func SessionFilter(c *revel.Controller, fc []revel.Filter) {
session := restoreSession(c.Request.Request)
// c.Session, 重新生成一個revel.Session給controller!!!
// Log("sessoin--------")
// LogJ(session)
revelSession := revel.Session(session) // 強製轉換 還是同一個對象, 但有個問題, 這樣Session.Id()方法是用revel的了
c.Session = revelSession
// 生成sessionId
c.Session.Id()
sessionWasEmpty := len(c.Session) == 0
// Make session vars available in templates as {{.session.xyz}}
c.RenderArgs["session"] = c.Session
fc[0](c, fc[1:])
// Store the signed session if it could have changed.
if len(c.Session) > 0 || !sessionWasEmpty {
// 轉換成lea.Session
session = Session(c.Session)
c.SetCookie(session.cookie())
}
}