websocket

package
v1.1.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package websocket provides WebSocket subscription management with API Gateway integration for real-time notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	ConnectionID string    `json:"connection_id" dynamodbav:"ConnectionID"`
	UserID       string    `json:"user_id" dynamodbav:"UserID"`
	ConnectedAt  time.Time `json:"connected_at" dynamodbav:"ConnectedAt"`
	LastSeen     time.Time `json:"last_seen" dynamodbav:"LastSeen"`
	TTL          int64     `json:"ttl" dynamodbav:"TTL"`
}

Connection represents a WebSocket connection

type InfrastructureEvent

type InfrastructureEvent struct {
	ID          string         `json:"id"`
	Type        string         `json:"type"`
	Severity    string         `json:"severity"`
	Service     string         `json:"service"`
	Region      string         `json:"region"`
	Description string         `json:"description"`
	Timestamp   time.Time      `json:"timestamp"`
	Metadata    map[string]any `json:"metadata"`
}

InfrastructureEvent represents an infrastructure event

type ModerationEvent

type ModerationEvent struct {
	ID          string         `json:"id"`
	Type        string         `json:"type"`
	Severity    string         `json:"severity"`
	ContentID   string         `json:"content_id"`
	UserID      string         `json:"user_id"`
	Description string         `json:"description"`
	Timestamp   time.Time      `json:"timestamp"`
	Metadata    map[string]any `json:"metadata"`
}

ModerationEvent represents a moderation event

type ModerationFilter

type ModerationFilter struct {
	Severity  []string `json:"severity"`
	Types     []string `json:"types"`
	UserID    string   `json:"user_id,omitempty"`
	ContentID string   `json:"content_id,omitempty"`
}

ModerationFilter filters moderation events

type PerformanceAlert

type PerformanceAlert struct {
	ID          string         `json:"id"`
	Type        string         `json:"type"`
	Severity    string         `json:"severity"`
	Service     string         `json:"service"`
	Metric      string         `json:"metric"`
	Value       float64        `json:"value"`
	Threshold   float64        `json:"threshold"`
	Description string         `json:"description"`
	Timestamp   time.Time      `json:"timestamp"`
	Metadata    map[string]any `json:"metadata"`
}

PerformanceAlert represents a performance alert

type Subscription

type Subscription struct {
	ConnectionID     string         `json:"connection_id" dynamodbav:"ConnectionID"`
	SubscriptionType string         `json:"subscription_type" dynamodbav:"SubscriptionType"`
	Filter           map[string]any `json:"filter" dynamodbav:"Filter"`
	CreatedAt        time.Time      `json:"created_at" dynamodbav:"CreatedAt"`
	TTL              int64          `json:"ttl" dynamodbav:"TTL"`
}

Subscription represents a subscription to events

type SubscriptionManager

type SubscriptionManager interface {
	SubscribeModerationQueue(connectionID string, filter ModerationFilter) error
	SubscribeThreatIntel(connectionID string) error
	SubscribePerformanceAlerts(connectionID string, severity string) error
	SubscribeInfrastructureEvents(connectionID string) error
	SubscribeCommunityNotes(connectionID string) error
	SubscribeTimeline(connectionID string) error
	SubscribeNotifications(connectionID string) error
	Unsubscribe(connectionID string, subscriptionType string) error
	PublishModerationEvent(event *ModerationEvent) error
	PublishThreatAlert(alert *ThreatAlert) error
	PublishPerformanceAlert(alert *PerformanceAlert) error
	PublishInfrastructureEvent(event *InfrastructureEvent) error
	HandleConnect(connectionID, userID string) error
	HandleDisconnect(connectionID string) error
}

SubscriptionManager manages WebSocket subscriptions

func NewSubscriptionManager

func NewSubscriptionManager(repo *repositories.WebSocketSubscriptionManagerRepository, apiGWEndpoint string, logger *zap.Logger) (SubscriptionManager, error)

NewSubscriptionManager creates a new subscription manager

type ThreatAlert

type ThreatAlert struct {
	ID          string         `json:"id"`
	Type        string         `json:"type"`
	Severity    string         `json:"severity"`
	Source      string         `json:"source"`
	Target      string         `json:"target"`
	Description string         `json:"description"`
	Indicators  []string       `json:"indicators"`
	Timestamp   time.Time      `json:"timestamp"`
	Metadata    map[string]any `json:"metadata"`
}

ThreatAlert represents a security threat alert

type WebSocketHandler

type WebSocketHandler struct {
	// contains filtered or unexported fields
}

WebSocketHandler handles API Gateway WebSocket events

func NewWebSocketHandler

func NewWebSocketHandler(sm SubscriptionManager, logger *zap.Logger) *WebSocketHandler

NewWebSocketHandler creates a new WebSocket handler

func (*WebSocketHandler) HandleAPIGatewayWebSocketEvent

HandleAPIGatewayWebSocketEvent handles WebSocket events from API Gateway

type WebSocketMessage

type WebSocketMessage struct {
	Type      string    `json:"type"`
	Data      any       `json:"data"`
	Timestamp time.Time `json:"timestamp"`
}

WebSocketMessage represents a message sent over WebSocket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL