AttachWebsocketRoute registers a websocket upgrade handler on the primary Gin engine. The handler is served as-is without additional middleware beyond the standard stack already configured.
(path string, handler http.Handler)
| 559 | // AttachWebsocketRoute registers a websocket upgrade handler on the primary Gin engine. |
| 560 | // The handler is served as-is without additional middleware beyond the standard stack already configured. |
| 561 | func (s *Server) AttachWebsocketRoute(path string, handler http.Handler) { |
| 562 | if s == nil || s.engine == nil || handler == nil { |
| 563 | return |
| 564 | } |
| 565 | trimmed := strings.TrimSpace(path) |
| 566 | if trimmed == "" { |
| 567 | trimmed = "/v1/ws" |
| 568 | } |
| 569 | if !strings.HasPrefix(trimmed, "/") { |
| 570 | trimmed = "/" + trimmed |
| 571 | } |
| 572 | s.wsRouteMu.Lock() |
| 573 | if _, exists := s.wsRoutes[trimmed]; exists { |
| 574 | s.wsRouteMu.Unlock() |
| 575 | return |
| 576 | } |
| 577 | s.wsRoutes[trimmed] = struct{}{} |
| 578 | s.wsRouteMu.Unlock() |
| 579 | |
| 580 | authMiddleware := AuthMiddleware(s.accessManager) |
| 581 | conditionalAuth := func(c *gin.Context) { |
| 582 | if !s.wsAuthEnabled.Load() { |
| 583 | c.Next() |
| 584 | return |
| 585 | } |
| 586 | authMiddleware(c) |
| 587 | } |
| 588 | finalHandler := func(c *gin.Context) { |
| 589 | handler.ServeHTTP(c.Writer, c.Request) |
| 590 | c.Abort() |
| 591 | } |
| 592 | |
| 593 | s.engine.GET(trimmed, conditionalAuth, finalHandler) |
| 594 | } |
| 595 | |
| 596 | func (s *Server) registerManagementRoutes() { |
| 597 | if s == nil || s.engine == nil || s.mgmt == nil { |
no test coverage detected