如何解决页面未将cookie会话保存在gorilla.sessions中
我将会话设置为cookie,但是刷新页面后,cookie消失了,这就是为什么如果cookie成功的话我不能使用该页面的原因,请寻求帮助,并在此先感谢您!
r.HandleFunc("/newroom",newRoomHandler)
func newRoomHandler(w http.ResponseWriter,r *http.Request) {
resultCheckCookie := sessionsTool.CheckAndUpdateSession(r,&w)
fmt.Println(resultCheckCookie)
if resultCheckCookie {
http.ServeFile(w,r,"templates/loginForm.html") //Проверка сессии в cookie
}
http.ServeFile(w,"templates/newPlanningPokerRoom.html")
}
func (s *SessionsTool) CheckAndUpdateSession(r *http.Request,w *http.ResponseWriter) bool {
s.currentSession,_ = s.sessionStore.Get(r,"session")
untyped,ok := s.currentSession.Values["UserLogin"]
if !ok {
return true
}
userLogin,ok := untyped.(string)
if !ok {
return true
}
fmt.Println(userLogin)
s.currentSession.Save(r,*w)
return false
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。