store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter implements the WebSocketAdapter interface, providing a high-level API for other modules to interact with WebSocket connections.

func NewAdapter

func NewAdapter(manager *connections.Manager, subs *Subscriptions, validators *ValidatorRegistry) *Adapter

NewAdapter creates a new Adapter.

func (*Adapter) Broadcast

func (a *Adapter) Broadcast(ctx context.Context, topic string, payload json.RawMessage, filter func(connections.Connection) bool)

Broadcast sends a message to all connections subscribed to the given topic, optionally filtering by a predicate.

func (*Adapter) GetConnections

func (a *Adapter) GetConnections(filter func(connections.Connection) bool) []connections.Connection

GetConnections returns all connections matching a filter predicate.

func (*Adapter) RegisterTopicValidator

func (a *Adapter) RegisterTopicValidator(pattern string, validator TopicValidatorFunc) error

RegisterTopicValidator registers an authorization callback for topics matching the given glob pattern. The callback receives the connection attempting to subscribe/publish and the full topic string. Return nil to allow, return an error to reject (the error message is sent to the client). If multiple patterns match a topic, all registered validators are called; any rejection blocks the operation. Patterns use the same glob syntax as allowedEventTypes (e.g. "qa.user.*", "qa.conversation.*").

func (*Adapter) SendTo

func (a *Adapter) SendTo(connID string, msg *protocol.ServerMessage) bool

SendTo sends a message to a specific connection by ID.

func (*Adapter) SendToTenant

func (a *Adapter) SendToTenant(tenantID string, msg *protocol.ServerMessage) int

SendToTenant sends a message to all connections of a specific tenant.

func (*Adapter) SendToUser

func (a *Adapter) SendToUser(userID string, msg *protocol.ServerMessage) int

SendToUser sends a message to all connections of a specific user.

type Subscriptions

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

Subscriptions tracks which connections are subscribed to which topics. Thread-safe via sync.Map.

func NewSubscriptions

func NewSubscriptions() *Subscriptions

NewSubscriptions creates a new Subscriptions store.

func (*Subscriptions) GetSubscribedConns

func (s *Subscriptions) GetSubscribedConns(eventType string) []string

GetSubscribedConns returns all connection IDs that should receive a message for the given event type. It checks each connection's subscribed topics using glob matching.

func (*Subscriptions) GetTopics

func (s *Subscriptions) GetTopics(connID string) []string

GetTopics returns all topics a connection is subscribed to.

func (*Subscriptions) Subscribe

func (s *Subscriptions) Subscribe(connID, topic string)

Subscribe adds a topic subscription for a connection.

func (*Subscriptions) TopicSubscriberCount

func (s *Subscriptions) TopicSubscriberCount(topic string) int

TopicSubscriberCount returns the number of connections subscribed to a topic (exact match, not glob).

func (*Subscriptions) Unsubscribe

func (s *Subscriptions) Unsubscribe(connID, topic string)

Unsubscribe removes a topic subscription for a connection.

func (*Subscriptions) UnsubscribeAll

func (s *Subscriptions) UnsubscribeAll(connID string)

UnsubscribeAll removes all subscriptions for a connection.

type TopicValidatorFunc

type TopicValidatorFunc func(ctx context.Context, conn connections.Connection, topic string) error

TopicValidatorFunc is called before a subscribe or publish is processed. conn is the authenticated connection; topic is the full topic string from the client message.

type ValidatorRegistry

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

ValidatorRegistry stores topic validators and executes matching ones during subscribe and publish operations. It is safe for concurrent reads; writes (registration) are expected only at module initialisation time.

func NewValidatorRegistry

func NewValidatorRegistry() *ValidatorRegistry

NewValidatorRegistry creates an empty ValidatorRegistry.

func (*ValidatorRegistry) Register

func (r *ValidatorRegistry) Register(pattern string, fn TopicValidatorFunc) error

Register adds a validator for topics matching the given glob pattern. The pattern must be non-empty and uses the same syntax as MatchTopic

func (*ValidatorRegistry) Validate

func (r *ValidatorRegistry) Validate(ctx context.Context, conn connections.Connection, topic string) error

Validate runs all registered validators whose pattern matches the given topic. If any validator returns a non-nil error the operation is rejected immediately. If no validators match the topic, nil is returned (allow by default).

Jump to

Keyboard shortcuts

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