mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-11 16:17:31 +02:00
http session context helper function.
This commit is contained in:
parent
40b986c8be
commit
7524f20cb7
1 changed files with 5 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue