简体   繁体   English

让 Revel controller 返回一个 cookie

[英]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.

相关问题 反应组件没有从异步方法获得回报 - react component not getting a return from asyncronous method React Native 获取 Firebase 数据只返回“object Object”? - React Native getting Firebase data only return "object Object"? 在没有Stateless/Stateful Widget的情况下获取Flutter中Future Function的返回值 - getting the return value of Future Function in Flutter without Stateless/Stateful Widget 谷歌 Cookie 解码 - Google Cookie decode 浏览器阻止 CORS cookie - Browsers block CORS cookie 调用 webhook“validate.nginx.ingress.kube.netes.io”失败:在 NginxIngress Controller 中应用入口资源/规则 yaml 文件时出错 - Getting failed calling webhook "validate.nginx.ingress.kubernetes.io": error when applying ingress resource/rules yaml file in NginxIngress Controller Go 与开发前端共享 cookie - Go share cookie with development frontend 我正在尝试使用 twilio-ruby gem 我可以从 Rails 控制台获取短信,但在我的 controller 中我收到了一个错误 - I am trying to use the twilio-ruby gem And I can get text messages to work from the Rails Console but In my controller I am a getting an error 将 js-cookie 值设置为 firebase 令牌 - set js-cookie value to firebase token 如何在 Azure 活动目录中设置 session cookie? - How to setup session cookie in Azure Active directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM