I am using gorilla/session and I need the session generated token(ID) which is going to be saved in cookies, as i want to save that token in database too. If I print the http response i.e fmt.Println(w), I’m able to see the session ID as:
&{0xc420204000 0xc42012e300 0xc420162840 0x118a4b0 false false false false 0xc420162280 {0xc4201a6460 map[] false false} map[Set-Cookie:[session=MTUyNzQ5MzA3M3xEdi1CQkFFQ180SUFBUkFCRUFBQUpmLUNBQUVHYzNSeWFXNW5EQW9BQ0hWelpYSnVZVzFsQm5OMGNtbHVad3dGQUFOaGMyUT18l1yx3yhYtbpiBRIagYseK80RSRC6warI07QxvmbuaDA=; Path=/; Expires=Wed, 27 Jun 2018 07:37:53 GMT; Max-Age=2592000]] true 0 -1 0 false false [] 0 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0] [0 0 0] 0xc4202140e0 0}
how to store this session ID in a variable, so that i can use it later.
func MyHandler(w http.ResponseWriter, r *http.Request) {
// Get a session. We're ignoring the error resulted from decoding an
// existing session: Get() always returns a session, even if empty.
session, _ := store.Get(r, "session-name")
// Set some session values.
session.Values["foo"] = "bar"
session.Values[42] = 43
// Save it before we write to the response/return from the handler.
session.Save(r, w)
}