mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
http session context helper function.
This commit is contained in:
parent
40b986c8be
commit
7524f20cb7
@ -47,7 +47,7 @@ func (api *ApiManagerCtx) Route(r chi.Router) {
|
|||||||
r.Route("/room", roomHandler.Route)
|
r.Route("/room", roomHandler.Route)
|
||||||
|
|
||||||
r.Get("/test", func(w http.ResponseWriter, r *http.Request) {
|
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.")
|
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…
Reference in New Issue
Block a user