mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-12 12:09:56 +01:00
44 lines
959 B
Go
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)
|
|
}
|
|
}
|