echo-contrib
echo-contrib copied to clipboard
session.Get will never get error
Today I use this package test the function of session, but I found when I firstly enter the website, in that time the request don't have session, but use Sesson.Get can't get error. But I think if the session is empty, maybe should return a error.
eg:
code: sess, err := session.Get("userInfo", c)
but in the first time the err is nil.
Can you answer my question?
Thanks.
maybe:
func getSession(sessionName, c echo.Context) (*sessions.Session, error) {
sess, _ := session.Get(sessionName, c)
if len(sess.Values) == 0 {
// no session
// log todo
return sess, errors.New("no session values")
}
return sess, nil
}