本文整理汇总了Golang中github.com/Unknwon/macaron.Context.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.SetCookie方法的具体用法?Golang Context.SetCookie怎么用?Golang Context.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/Unknwon/macaron.Context
的用法示例。
在下文中一共展示了Context.SetCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Validate
// Validate should be used as a per route middleware. It attempts to get a token from a "X-CSRFToken"
// HTTP header and then a "_csrf" form value. If one of these is found, the token will be validated
// using ValidToken. If this validation fails, custom Error is sent in the reply.
// If neither a header or form value is found, http.StatusBadRequest is sent.
func Validate(ctx *macaron.Context, x CSRF) {
if token := ctx.Req.Header.Get(x.GetHeaderName()); token != "" {
if !x.ValidToken(token) {
ctx.SetCookie(x.GetCookieName(), "", -1, x.GetCookiePath())
x.Error(ctx.Resp)
}
return
}
if token := ctx.Req.FormValue(x.GetFormName()); token != "" {
if !x.ValidToken(token) {
ctx.SetCookie(x.GetCookieName(), "", -1, x.GetCookiePath())
x.Error(ctx.Resp)
}
return
}
http.Error(ctx.Resp, "Bad Request: no CSRF token represnet", http.StatusBadRequest)
}
示例2: setCookie
func setCookie(ctx *macaron.Context) {
ctx.SetCookie("user", "wuwen")
}
示例3: mySetCookieHandler
func mySetCookieHandler(ctx *macaron.Context) string {
// set the cookie for 5 minutes
ctx.SetCookie("user", ctx.Params(":value"), 300)
return "cookie set for 5 minutes"
}