AddRouter in API.

This commit is contained in:
Miroslav Šedivý 2020-12-12 17:07:45 +01:00
parent 9786c8d537
commit af463b1015

View File

@ -17,6 +17,7 @@ type ApiManagerCtx struct {
sessions types.SessionManager
desktop types.DesktopManager
capture types.CaptureManager
routers map[string]func(chi.Router)
}
func New(
@ -30,6 +31,7 @@ func New(
sessions: sessions,
desktop: desktop,
capture: capture,
routers: make(map[string]func(chi.Router)),
}
}
@ -46,6 +48,10 @@ func (api *ApiManagerCtx) Route(r chi.Router) {
session := auth.GetSession(r)
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 {
@ -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
}