[英]Getting Revel controller to return a cookie
I've been able to store a custom cookie but I'm trying to save it for a session the store it in the database when a form is submitted.我已经能够存储自定义 cookie,但我试图将其保存为 session,并在提交表单时将其存储在数据库中。 I use:
我用:
func (c Application) Index(id string) revel.Result {
cookie := http.Cookie{Name: "id", Value: id, Domain: "localhost", Path: "/"}
c.SetCookie(&cookie)
return c.Render()
}
but I cannot access it again.但我无法再次访问它。 How could I retrieve it in a different function?
我怎样才能在不同的 function 中检索它?
Thank you!谢谢!
I was going about it all wrong.我做错了。 Revel sets cookies with the session.
Revel 将 cookies 与 session 组合在一起。
Set:
c.Session[key] = value
Get:
c.Session[key]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.