mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
AddRouter in API.
This commit is contained in:
parent
9786c8d537
commit
af463b1015
@ -14,9 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ApiManagerCtx struct {
|
type ApiManagerCtx struct {
|
||||||
sessions types.SessionManager
|
sessions types.SessionManager
|
||||||
desktop types.DesktopManager
|
desktop types.DesktopManager
|
||||||
capture types.CaptureManager
|
capture types.CaptureManager
|
||||||
|
routers map[string]func(chi.Router)
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(
|
func New(
|
||||||
@ -27,9 +28,10 @@ func New(
|
|||||||
) *ApiManagerCtx {
|
) *ApiManagerCtx {
|
||||||
|
|
||||||
return &ApiManagerCtx{
|
return &ApiManagerCtx{
|
||||||
sessions: sessions,
|
sessions: sessions,
|
||||||
desktop: desktop,
|
desktop: desktop,
|
||||||
capture: capture,
|
capture: capture,
|
||||||
|
routers: make(map[string]func(chi.Router)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +48,10 @@ func (api *ApiManagerCtx) Route(r chi.Router) {
|
|||||||
session := auth.GetSession(r)
|
session := auth.GetSession(r)
|
||||||
utils.HttpBadRequest(w, "Hi `" + session.ID() + "`, you are authenticated.")
|
utils.HttpBadRequest(w, "Hi `" + session.ID() + "`, you are authenticated.")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for path, router := range api.routers {
|
||||||
|
r.Route(path, router)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler {
|
func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler {
|
||||||
@ -58,3 +64,7 @@ func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *ApiManagerCtx) AddRouter(path string, router func(chi.Router)) {
|
||||||
|
api.routers[path] = router
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user