diff options
Diffstat (limited to '')
-rw-r--r-- | session.go | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -11,10 +11,11 @@ import ( "github.com/gorilla/sessions" ) +type sessionContextKey struct{} + const ( - sessionCookie = "sessionKeks" - sessionContextKey = "_session" - dataKey = "data" + sessionCookie = "sessionKeks" + dataKey = "data" ) func init() { @@ -48,7 +49,7 @@ func (s *Session) Invalidate() { } func session(r *http.Request) Session { - s := r.Context().Value(sessionContextKey).(*sessions.Session) + s := r.Context().Value(sessionContextKey{}).(*sessions.Session) s.Options.HttpOnly = true sd, ok := s.Values[dataKey].(SessionData) @@ -72,7 +73,7 @@ func sessionHandler(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session, _ := sessionStore.Get(r, sessionCookie) - ctx := context.WithValue(r.Context(), sessionContextKey, session) + ctx := context.WithValue(r.Context(), sessionContextKey{}, session) next.ServeHTTP(w, r.WithContext(ctx)) }) } |