Documentation
¶
Overview ¶
Package hub provides a WebSocket hub for managing client connections and broadcasting GitHub webhook events to subscribed clients based on their subscription criteria.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidUsername indicates an invalid GitHub username. ErrInvalidUsername = errors.New("invalid username") // ErrInvalidURL indicates an invalid URL. ErrInvalidURL = errors.New("invalid URL") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { ID string // contains filtered or unexported fields }
Client represents a connected WebSocket client with their subscription preferences.
type Event ¶
type Event struct { URL string `json:"url"` // Pull request URL Timestamp time.Time `json:"timestamp"` // When the event occurred Type string `json:"type"` // GitHub event type (e.g., "pull_request") }
Event represents a GitHub webhook event that will be broadcast to clients. It contains the PR URL, timestamp, and event type from GitHub.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub manages WebSocket clients and event broadcasting. It runs in its own goroutine and handles client registration, unregistration, and event distribution.
func (*Hub) Run ¶
Run starts the hub's event loop. The context should be passed from main for proper lifecycle management.
func (*Hub) Unregister ¶
Unregister unregisters a client by ID.
type Subscription ¶
type Subscription struct { Organization string `json:"organization"` Username string `json:"-"` EventTypes []string `json:"event_types,omitempty"` UserEventsOnly bool `json:"user_events_only,omitempty"` PullRequests []string `json:"pull_requests,omitempty"` // List of PR URLs to subscribe to }
Subscription represents a client's subscription criteria.
func (*Subscription) Validate ¶
func (s *Subscription) Validate() error
Validate performs security validation on subscription data.
type WebSocketHandler ¶
type WebSocketHandler struct {
// contains filtered or unexported fields
}
WebSocketHandler handles WebSocket connections.
func NewWebSocketHandler ¶
func NewWebSocketHandler(h *Hub, connLimiter *security.ConnectionLimiter, allowedEvents []string) *WebSocketHandler
NewWebSocketHandler creates a new WebSocket handler.
func NewWebSocketHandlerForTest ¶
func NewWebSocketHandlerForTest(h *Hub, connLimiter *security.ConnectionLimiter, allowedEvents []string) *WebSocketHandler
NewWebSocketHandlerForTest creates a WebSocket handler for testing that skips GitHub auth.
func (*WebSocketHandler) Handle ¶
func (h *WebSocketHandler) Handle(ws *websocket.Conn)
Handle handles a WebSocket connection.