events

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package events provides protocol event pub/sub and webhook notifications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatEvent

func FormatEvent(e *Event) string

FormatEvent formats an event for display.

Types

type Event

type Event struct {
	ID        string    `json:"id"`
	Type      EventType `json:"type"`
	Protocol  string    `json:"protocol"`
	Timestamp time.Time `json:"timestamp"`
	Data      any       `json:"data"`
}

Event represents a protocol event.

type EventBus

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

EventBus manages event pub/sub.

func NewEventBus

func NewEventBus() *EventBus

NewEventBus creates a new event bus.

func (*EventBus) AddWebhook

func (eb *EventBus) AddWebhook(wh Webhook)

AddWebhook registers a webhook.

func (*EventBus) Publish

func (eb *EventBus) Publish(e *Event)

Publish publishes an event.

func (*EventBus) Replay

func (eb *EventBus) Replay(filter *FilterRule) []*Event

Replay replays historical events.

func (*EventBus) Subscribe

func (eb *EventBus) Subscribe(id string) chan *Event

Subscribe subscribes to events.

func (*EventBus) Unsubscribe

func (eb *EventBus) Unsubscribe(id string)

Unsubscribe removes a subscriber.

type EventType

type EventType string

EventType represents the type of protocol event.

const (
	EventProtocolChanged EventType = "protocol.changed"
	EventDecodeError     EventType = "decode.error"
	EventValidation      EventType = "validation.complete"
)

type FilterRule

type FilterRule struct {
	Types     []EventType `json:"types,omitempty"`
	Protocols []string    `json:"protocols,omitempty"`
}

FilterRule defines an event filter.

func (*FilterRule) Match

func (f *FilterRule) Match(e *Event) bool

Match checks if an event matches the filter.

type Webhook

type Webhook struct {
	URL    string     `json:"url"`
	Filter FilterRule `json:"filter"`
}

Webhook represents a webhook endpoint.

Jump to

Keyboard shortcuts

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