sse

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// Connection states
	StatusConnected    = "connected"
	StatusDisconnected = "disconnected"
	StatusReconnecting = "reconnecting"

	// Information states
	StatusInfo    = "info"
	StatusWarning = "warning"
	StatusError   = "error"
	StatusSuccess = "success"
	StatusDebug   = "debug"

	// Process states
	StatusStarted    = "started"
	StatusProcessing = "processing"
	StatusCompleted  = "completed"
	StatusCancelled  = "cancelled"
	StatusPaused     = "paused"
	StatusResumed    = "resumed"

	// Data states
	StatusCreated  = "created"
	StatusUpdated  = "updated"
	StatusDeleted  = "deleted"
	StatusArchived = "archived"

	// System states
	StatusHealthy     = "healthy"
	StatusDegraded    = "degraded"
	StatusMaintenance = "maintenance"
)

Status constants for common event states

Variables

This section is empty.

Functions

func Send

func Send(path string, clientID int64, data interface{})

Send broadcasts an event to a specific client on a specific path

func SendAlert

func SendAlert(path string, clientID int64, title, message string, level EventLevel)

SendAlert sends an alert event to a specific client on a specific path

func SendProgress

func SendProgress(path string, clientID int64, percent, currentStep, totalSteps int, description string)

SendProgress sends a progress update event to a specific client on a specific path

func SendToPath

func SendToPath(path string, data interface{})

SendToPath sends an event to all clients subscribed to a specific path

func SendToPathWithMetadata

func SendToPathWithMetadata(path string, status string, data interface{}, metadata *EventMetadata)

SendToPathWithMetadata sends an event with metadata to all clients on a specific path

func SendToPathWithStatus

func SendToPathWithStatus(path string, status string, data interface{})

SendToPathWithStatus sends an event with a status to all clients on a specific path

func SendWithMetadata

func SendWithMetadata(path string, clientID int64, status string, data interface{}, metadata *EventMetadata)

SendWithMetadata sends an event with full metadata to a specific client on a specific path

func SendWithStatus

func SendWithStatus(path string, clientID int64, status string, data interface{})

SendWithStatus sends an event with additional status metadata to a specific client on a specific path

Types

type AlertEvent

type AlertEvent struct {
	Title      string    `json:"title"`
	Message    string    `json:"message"`
	Level      string    `json:"level"`
	ActionURL  string    `json:"actionUrl,omitempty"`
	Expiration time.Time `json:"expiration,omitempty"`
	Time       time.Time `json:"time"`
}

AlertEvent represents an alert or notification

type Event

type Event struct {
	ID       string         `json:"id"`
	Status   string         `json:"status"`
	Time     time.Time      `json:"time"`
	Data     interface{}    `json:"data,omitempty"`
	Metadata *EventMetadata `json:"metadata,omitempty"`
}

Event represents a server-sent event with metadata

type EventHub

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

EventHub manages per-path and per-client event delivery

var EventHubInstance *EventHub

EventHubInstance is the central hub for managing connections and events. Ensure that this is initialized and injected by the application.

func NewEventHub

func NewEventHub() *EventHub

NewEventHub initializes a new EventHub

func (*EventHub) Broadcast

func (hub *EventHub) Broadcast(path string, clientID int64, event interface{})

Broadcast sends an event to a specific client on a specific path

func (*EventHub) BroadcastAll

func (hub *EventHub) BroadcastAll(event interface{})

BroadcastAll sends an event to all clients across all paths

func (*EventHub) BroadcastPath

func (hub *EventHub) BroadcastPath(path string, event interface{})

BroadcastPath sends an event to all clients subscribed to a specific path

func (*EventHub) Subscribe

func (hub *EventHub) Subscribe(path string, clientID int64) chan interface{}

Subscribe adds a new subscriber for a specific path and client

func (*EventHub) Unsubscribe

func (hub *EventHub) Unsubscribe(path string, clientID int64)

Unsubscribe removes a subscriber for a specific path and client

type EventLevel

type EventLevel int

EventLevel represents the severity/importance of an event

const (
	LevelDebug EventLevel = iota
	LevelInfo
	LevelWarning
	LevelError
	LevelCritical
)

type EventMetadata

type EventMetadata struct {
	Level       EventLevel `json:"level,omitempty"`
	Source      string     `json:"source,omitempty"`
	Category    string     `json:"category,omitempty"`
	RetryCount  int        `json:"retryCount,omitempty"`
	Version     string     `json:"version,omitempty"`
	Environment string     `json:"environment,omitempty"`
}

EventMetadata contains additional information about the event

type ProgressEvent

type ProgressEvent struct {
	Percent       int    `json:"percent"`
	CurrentStep   int    `json:"currentStep"`
	TotalSteps    int    `json:"totalSteps"`
	Description   string `json:"description,omitempty"`
	TimeRemaining string `json:"timeRemaining,omitempty"`
}

ProgressEvent represents a progress update

Jump to

Keyboard shortcuts

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