【发布时间】:2015-05-22 07:27:07
【问题描述】:
我正在尝试实现会话处理并将其与 go-endpoints 包结合起来!
我用来处理会话的包是 Gorilla Sessions (github.com/gorilla/sessions),我需要一些帮助..
我能够将 cookie 存储到客户端......当我调用端点时可以看到 cookie 被发送到服务器。
当我在调用 api 时尝试从 Session 存储中获取 Session 值时出现问题,我无法被扔到 cookie 中。它接缝的是端点包从额外的内容或其他东西中剥离了 http.Request 。 ?
我尝试获取 cookie 的位置在 Server.go 中
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request){
var store = sessions.NewCookieStore([]byte("secret123"));
session, _ := store.Get(r, "session-name");
// Get the previously flashes, if any.
c.Infof("foo value is : %v",r.Cookies());
if flashes := session.Flashes(); len(flashes) > 0 {
// Just print the flash values.
c.Infof("this is the testing post message with cookie from the ServeHTTP :
%v",flashes);
}
else {
// Set a new flash.
session.AddFlash("Hello, flash messages world!")
c.Infof("No flashes found.");
}
session.Save(r, w)
}
我得到的是一个空数组.... :(
有人有线索吗?
谢谢!!!!!!
【问题讨论】:
-
不要忽略错误。检查它在说什么。那,并且您的“商店”变量正在根据每个请求进行更新。它需要是全局的(简单的)或在应用程序范围的上下文中定义的。
-
好的!我会尝试并发布更新!谢谢!
标签: session cookies go google-cloud-endpoints gorilla