I am trying to set a gorilla session and then retreive the value again. I am doing the following just as a test.
//create session and store in http Cookies
session, err := store.Get(req, "session")
if err != nil {
errCode = http.StatusInternalServerError
return
}
//save a value
session.Values["user_id"] = userTuple.UserId
err = session.Save(req, w)
if err != nil {
errCode = http.StatusInternalServerError
return
}
//try to get the same session that was just created
nr := http.Request{Header: w.Header()}
session, err = store.Get(&nr, "session")
if err != nil {
errCode = http.StatusInternalServerError
return
} else if session.IsNew {
log.Println("New session created instead of old one.")
}
This is a snippet out of a larger HTTP handler. But the relavent parts are posted and the the second call to store.Get()
is not returning an existing session, but a brand new one. Hence, when the handler this code is in is executed, the log statements is printed to console.
Why am I getting a new session in this case instead of the one I had already created and saved?