2fas-server/internal/websocket/app.go
2022-12-31 10:22:38 +01:00

44 lines
959 B
Go

package websocket
import (
"github.com/2fas/api/internal/common/http"
"github.com/2fas/api/internal/websocket/browser_extension"
"github.com/2fas/api/internal/websocket/common"
"github.com/gin-gonic/gin"
)
type Server struct {
router *gin.Engine
addr string
connectionHandler *common.ConnectionHandler
}
func NewServer(addr string) *Server {
router := gin.New()
router.Use(gin.Recovery())
router.Use(http.RequestIdMiddleware())
router.Use(http.CorrelationIdMiddleware())
router.Use(http.RequestJsonLogger())
connectionHandler := common.NewConnectionHandler()
routesHandler := browser_extension.NewRoutesHandler(connectionHandler)
browser_extension.GinRoutesHandler(routesHandler, router)
return &Server{
router: router,
addr: addr,
connectionHandler: connectionHandler,
}
}
func (s *Server) RunWebsocketServer() {
err := s.router.Run(s.addr)
if err != nil {
panic(err)
}
}