http://www.gorillatoolkit.org/pkg/sessions
https://github.com/gorilla/sessions
I use gorilla for session management in Golang.
I'd like to discard all my sessions and then save the data to a new session.
I don't know how to discard the session at that time, so please let me know if anyone knows.
funclearSession1(session*sessions.Session){
session.Options=&sessions.Options {MaxAge:-1, Path: "/"}
}
/*
In the first way, the session is not erased immediately.
be deleted after processing a request
*/
US>funclearSession2(session*sessions.Session){
session.Values=nil
}
/*
In the second way, the session can be deleted immediately, but the following error occurs when saving to the session again.
panic:runtime error:assignment to entry in null map
*/
After changing session.Options
,
session.Save()
will do what you want.
funclearSession1 (w http.ResponseWriter, r*http.Requset, session*sessions.Session) {
session.Options=&sessions.Options {MaxAge:-1, Path: "/"}
session.Save(r,w)
}
© 2024 OneMinuteCode. All rights reserved.