neko/internal/api/router.go

43 lines
893 B
Go
Raw Normal View History

2020-10-30 10:23:30 +13:00
package api
import (
"github.com/go-chi/chi"
2020-10-31 06:16:21 +13:00
"demodesk/neko/internal/api/member"
"demodesk/neko/internal/api/room"
"demodesk/neko/internal/types"
2020-10-30 10:23:30 +13:00
)
2020-10-31 06:16:21 +13:00
type API struct {
sessions types.SessionManager
remote types.RemoteManager
broadcast types.BroadcastManager
websocket types.WebSocketHandler
2020-10-30 10:23:30 +13:00
}
2020-10-31 06:16:21 +13:00
func New(
sessions types.SessionManager,
remote types.RemoteManager,
broadcast types.BroadcastManager,
websocket types.WebSocketHandler,
) *API {
// Init
return &API{
sessions: sessions,
remote: remote,
broadcast: broadcast,
websocket: websocket,
}
2020-10-30 10:23:30 +13:00
}
2020-10-31 06:16:21 +13:00
func (a *API) Mount(router *chi.Mux) {
// all member routes
memberHandler := member.New(a.sessions, a.websocket)
router.Mount("/member", memberHandler.Router())
2020-10-30 10:23:30 +13:00
2020-10-31 06:16:21 +13:00
// get room routes
roomHandler := room.New(a.sessions, a.remote, a.broadcast, a.websocket)
router.Mount("/room", roomHandler.Router())
2020-10-30 10:23:30 +13:00
}