diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-03 20:56:42 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-03 20:56:42 +0200 |
commit | 34caf591edc400add9f7dab493902db4333c9abc (patch) | |
tree | 7449209a1b71a52cb19e3c5f36f2b35db2b44ad8 /session | |
parent | 168cd2f96f39295b9c96594784719fcb72607a00 (diff) | |
download | gosten-34caf591edc400add9f7dab493902db4333c9abc.tar.gz gosten-34caf591edc400add9f7dab493902db4333c9abc.tar.bz2 gosten-34caf591edc400add9f7dab493902db4333c9abc.zip |
Yet another place where a string constant is replaced by a unique type
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)) }) } |