From 34caf591edc400add9f7dab493902db4333c9abc Mon Sep 17 00:00:00 2001 From: René 'Necoro' Neumann Date: Thu, 3 Oct 2024 20:56:42 +0200 Subject: Yet another place where a string constant is replaced by a unique type --- session.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'session.go') diff --git a/session.go b/session.go index 3718623..680f648 100644 --- a/session.go +++ b/session.go @@ -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)) }) } -- cgit v1.2.3-70-g09d2