summaryrefslogtreecommitdiff
path: root/session.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:56:42 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-03 20:56:42 +0200
commit34caf591edc400add9f7dab493902db4333c9abc (patch)
tree7449209a1b71a52cb19e3c5f36f2b35db2b44ad8 /session.go
parent168cd2f96f39295b9c96594784719fcb72607a00 (diff)
downloadgosten-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 'session.go')
-rw-r--r--session.go11
1 files changed, 6 insertions, 5 deletions
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))
})
}