From 7524f20cb74abdc14cd377896071feb773eca7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 14 Nov 2020 18:22:15 +0100 Subject: [PATCH] http session context helper function. --- internal/api/router.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/api/router.go b/internal/api/router.go index b96d3052..08eabff2 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -47,7 +47,7 @@ func (api *ApiManagerCtx) Route(r chi.Router) { r.Route("/room", roomHandler.Route) r.Get("/test", func(w http.ResponseWriter, r *http.Request) { - session, _ := r.Context().Value(keySessionCtx).(types.Session) + session := GetSession(r) utils.HttpBadRequest(w, "Hi `" + session.ID() + "`, you are authenticated.") }) } @@ -63,3 +63,7 @@ func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler { } }) } + +func GetSession(r *http.Request) types.Session { + return r.Context().Value(keySessionCtx).(types.Session) +}