我正在嘗試實現會話處理并將其與 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) }我得到的是一個空數組....:(有人有線索嗎?謝謝 ?。。。。?
- 1 回答
- 0 關注
- 176 瀏覽
添加回答
舉報
0/150
提交
取消