echo-contrib icon indicating copy to clipboard operation
echo-contrib copied to clipboard

session.Get will never get error

Open zn-cn opened this issue 7 years ago • 1 comments

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.

zn-cn avatar Jul 17 '18 05:07 zn-cn

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
}

zn-cn avatar Jul 17 '18 05:07 zn-cn