sessions icon indicating copy to clipboard operation
sessions copied to clipboard

redigo: get on closed pool

Open xujb977644703 opened this issue 2 years ago • 2 comments

// Add a value session.Values["foo"] = "bar"

// Save session
if err = sessions.Save(req, w); err != nil {
	log.Fatal("failed saving session: ", err)
}

when the "bar" is interface{},the session.save is err,why?

xujb977644703 avatar Jun 29 '22 07:06 xujb977644703

Don’t ignore the error here:

store, _ = redistore.NewRediStore(c.Redis.Db, "tcp", c.Redis.Addr, "", []byte("secret-keyS"))

elithrar avatar Jun 29 '22 10:06 elithrar

@xujb977644703 what is the error message?

amustaque97 avatar Jun 29 '22 18:06 amustaque97

@xujb977644703 I am not getting the error when using interface. Can you provide some code with which we can reproduce the error you would be facing?

func MyHandler(w http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, "session-name")
	var a interface{}
	session.Values["foo"] = a
	session.Values[42] = 43
	err := session.Save(r, w)
	if err != nil {
		log.Default().Println(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}

bharat-rajani avatar Apr 18 '24 19:04 bharat-rajani