I am working on an auth package called persona.
Every thing works fine except one thing, when I try to set a cookie, I have an invalid memory address.
func Signup(user interface{}, username string, w http.ResponseWriter) error {
key := []byte(randStringBytes(32))
encrypted, err := encrypt(key, username)
if err != nil {
return err
}
expiration := time.Now().Add(365 * 24 * time.Hour)
cookie := http.Cookie{Name: "session-persona", Value: encrypted, Expires: expiration}
http.SetCookie(w, &cookie)
userSession := Session{Username: username, Key: key, Token: encrypted}
database.Create(&userSession)
database.Create(user)
return nil
}
When I remove http.SetCookie(w, &cookie)
everything works fine.
Do you have any idea ?
I think the problem might not be the
http.Cookie
object, but perhaps theResponseWriter
object (sinceResponseWriter
is an interface). For debugging, try checking it fornil
before setting the Cookie. If it isnil
, you’ll probably have to look up the stack from `Signup’ to figure out why - perhaps it had already been closed.