websocket api: split connection handler per route

This commit is contained in:
in-void 2023-03-07 23:34:29 +01:00
parent 254ce8546c
commit b8dd4c167a
2 changed files with 4 additions and 6 deletions

View File

@ -16,10 +16,8 @@ func NewRoutesHandler(handler *common.ConnectionHandler) *RoutesHandler {
}
func GinRoutesHandler(routes *RoutesHandler, router *gin.Engine) {
connectionHandler := routes.connectionHandler.Handle()
router.GET("/browser_extensions/:extension_id", connectionHandler)
router.GET("/browser_extensions/:extension_id/2fa_requests/:token_request_id", connectionHandler)
router.GET("/browser_extensions/:extension_id", routes.connectionHandler.Handler())
router.GET("/browser_extensions/:extension_id/2fa_requests/:token_request_id", routes.connectionHandler.Handler())
router.GET("/health", func(c *gin.Context) {
c.String(200, "")

View File

@ -35,7 +35,7 @@ func NewConnectionHandler() *ConnectionHandler {
}
}
func (h *ConnectionHandler) Handle() gin.HandlerFunc {
func (h *ConnectionHandler) Handler() gin.HandlerFunc {
return func(c *gin.Context) {
channel := c.Request.URL.Path
@ -81,7 +81,7 @@ func (h *ConnectionHandler) serveWs(hub *Hub, w http.ResponseWriter, r *http.Req
<-time.After(disconnectAfter)
defer func() {
logging.Info("Connection closed after", disconnectAfter, "minutes")
logging.Info("Connection closed after", disconnectAfter)
client.hub.unregister <- client
client.conn.Close()