Documentation
¶
Index ¶
- Constants
- type Bus
- func (b *Bus) Close()
- func (b *Bus) Publish(e Event)
- func (b *Bus) PublishSync(e Event)
- func (b *Bus) Stats() Stats
- func (b *Bus) Subscribe(eventType EventType, handler Handler) string
- func (b *Bus) SubscribeAll(handler Handler) string
- func (b *Bus) SubscribeMultiple(eventTypes []EventType, handler Handler) []string
- func (b *Bus) Unsubscribe(id string) bool
- type Event
- type EventType
- type Handler
- type Severity
- type Stats
- type Subscription
Constants ¶
const ( DefaultWorkerCount = 16 // Number of worker goroutines DefaultQueueSize = 1024 // Size of event dispatch queue )
Default worker pool settings
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is the central event distributor
func NewWithConfig ¶ added in v1.0.22
NewWithConfig creates a new event bus with custom worker pool settings
func (*Bus) Close ¶
func (b *Bus) Close()
Close stops the bus from accepting new events and shuts down workers
func (*Bus) Publish ¶
Publish sends an event to all matching subscribers Handlers are called asynchronously via the worker pool Non-blocking: if the queue is full, the event dispatch is dropped (backpressure)
func (*Bus) PublishSync ¶
PublishSync sends an event and waits for all handlers to complete Use sparingly - blocks the caller
func (*Bus) Subscribe ¶
Subscribe registers a handler for a specific event type Returns a subscription ID that can be used to unsubscribe
func (*Bus) SubscribeAll ¶
SubscribeAll registers a handler for ALL events Useful for logging, metrics, GUI updates
func (*Bus) SubscribeMultiple ¶
SubscribeMultiple registers a handler for multiple event types
func (*Bus) Unsubscribe ¶
Unsubscribe removes a subscription by ID
type Event ¶
type Event struct {
ID string `json:"id"` // Unique event ID
Type EventType `json:"type"` // Event type for routing
Severity Severity `json:"severity"` // Severity level
Timestamp time.Time `json:"timestamp"` // When event occurred
Source string `json:"source"` // Module that generated event
IP string `json:"ip"` // Related IP address (if any)
User string `json:"user"` // Related username (if any)
Message string `json:"message"` // Human-readable message
Data map[string]any `json:"data"` // Additional structured data
}
Event is the universal event structure passed between modules
func (Event) WithMessage ¶
WithMessage sets the Message field
func (Event) WithSeverity ¶
WithSeverity sets the Severity field
type EventType ¶
type EventType string
EventType categorizes events for routing
const ( // Ban/Unban events EventBan EventType = "ban" EventUnban EventType = "unban" // Login events EventLoginFail EventType = "login_fail" EventLoginFailed EventType = "login_failed" // Alias for consistency EventLoginSuccess EventType = "login_success" EventLoginAlert EventType = "login_alert" // Security detection events EventSuricataAlert EventType = "suricata_alert" EventDDoSDetected EventType = "ddos_detected" EventPortscan EventType = "portscan_detected" // Feed events EventFeedSync EventType = "feed_sync" EventFeedUpdate EventType = "feed_update" // System events EventHealthCheck EventType = "health_check" EventModuleStart EventType = "module_start" EventModuleStop EventType = "module_stop" EventError EventType = "error" // GeoIP events EventGeoIPUpdate EventType = "geoip_update" EventCountryBan EventType = "country_ban" )
type Stats ¶
type Stats struct {
Subscriptions int `json:"subscriptions"`
Workers int `json:"workers"`
QueueSize int `json:"queue_size"`
QueueUsed int `json:"queue_used"`
Published int64 `json:"published"`
Delivered int64 `json:"delivered"`
Dropped int64 `json:"dropped"` // Events dropped due to backpressure
Errors int64 `json:"errors"`
}
Stats returns bus statistics
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a registered handler