Documentation
¶
Overview ¶
Package events provides a simple Server-Sent Events (SSE) broker for real-time event streaming.
Index ¶
- func FormatSSE(event Event) string
- type BroadcastEvent
- type BroadcastPayload
- type Broker
- type Client
- type Event
- type PublishConfig
- type Publisher
- func (p *Publisher) PublishEvent(topic, eventType string, data map[string]interface{}) error
- func (p *Publisher) PublishEventAsync(topic, eventType string, data map[string]interface{})
- func (p *Publisher) PublishRiskEvent(eventType string, data map[string]interface{})
- func (p *Publisher) PublishTransactionEvent(eventType string, transactionID string, data map[string]interface{})
- func (p *Publisher) PublishUserEvent(eventType string, userID string, data map[string]interface{})
- func (p *Publisher) PublishWalletEvent(eventType string, walletID string, data map[string]interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BroadcastEvent ¶
BroadcastEvent represents an event to be broadcasted to clients.
type BroadcastPayload ¶
type BroadcastPayload struct {
Topic string `json:"topic"`
Type string `json:"type"`
Data map[string]interface{} `json:"data"`
}
BroadcastPayload represents the JSON payload for broadcasting events.
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker manages SSE connections and event broadcasting.
func (*Broker) GetClientCount ¶
GetClientCount returns the number of connected clients.
func (*Broker) Stop ¶
func (b *Broker) Stop()
Stop stops the broker and closes all client connections.
func (*Broker) Unregister ¶
Unregister removes a client from the broker.
type Client ¶
type Client struct {
ID string
Channel chan Event
Topics map[string]bool // Topics this client is subscribed to
// contains filtered or unexported fields
}
Client represents a connected SSE client.
func (*Client) IsSubscribed ¶
IsSubscribed checks if client is subscribed to a topic.
func (*Client) Unsubscribe ¶
Unsubscribe removes a topic from this client's subscriptions.
type Event ¶
type Event struct {
Type string `json:"type"`
Data map[string]interface{} `json:"data"`
Timestamp time.Time `json:"timestamp"`
}
Event represents a single event to be broadcasted.
type PublishConfig ¶
PublishConfig configures the event publisher.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher publishes events to the Gateway's SSE broker.
func NewPublisher ¶
func NewPublisher(config PublishConfig) *Publisher
NewPublisher creates a new event publisher.
func (*Publisher) PublishEvent ¶
PublishEvent publishes an event to the SSE broker via the Gateway. Topic determines which subscribers receive the event. EventType is the event name (e.g., "transaction.created"). Data contains the event payload.
func (*Publisher) PublishEventAsync ¶
PublishEventAsync publishes an event asynchronously (fire and forget). Errors are logged but not returned.
func (*Publisher) PublishRiskEvent ¶
PublishRiskEvent publishes a risk-related event.
func (*Publisher) PublishTransactionEvent ¶
func (p *Publisher) PublishTransactionEvent(eventType string, transactionID string, data map[string]interface{})
PublishTransactionEvent publishes a transaction-related event.
func (*Publisher) PublishUserEvent ¶
PublishUserEvent publishes a user-related event.