2022-12-31 10:22:38 +01:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-01-04 13:26:42 +01:00
|
|
|
|
2023-01-30 19:59:42 +01:00
|
|
|
"github.com/twofas/2fas-server/internal/common/http"
|
2023-04-11 23:37:36 +02:00
|
|
|
"github.com/twofas/2fas-server/internal/common/recovery"
|
2023-01-30 19:59:42 +01:00
|
|
|
"github.com/twofas/2fas-server/internal/websocket/browser_extension"
|
|
|
|
"github.com/twofas/2fas-server/internal/websocket/common"
|
2022-12-31 10:22:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
router *gin.Engine
|
|
|
|
addr string
|
|
|
|
connectionHandler *common.ConnectionHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewServer(addr string) *Server {
|
|
|
|
router := gin.New()
|
|
|
|
|
2023-04-11 23:37:36 +02:00
|
|
|
router.Use(recovery.RecoveryMiddleware())
|
2024-03-16 19:05:21 +01:00
|
|
|
router.Use(http.LoggingMiddleware())
|
2022-12-31 10:22:38 +01:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|