Skip to content

realtime

go
import "github.com/nathabonfim59/pbvex/backend/internal/realtime"

Package realtime implements the PBVex SSE realtime endpoint.

Index

Variables

go
var (
    ErrArgsNotJSON      = errors.New("args is not valid JSON")
    ErrArgsNotCanonical = errors.New("args is not canonical JSON")
    ErrArgsInvalid      = errors.New("invalid args")
)

func DeriveSubscriptionID

go
func DeriveSubscriptionID(version, path string, args any) string

DeriveSubscriptionID is a test/export helper that canonicalizes args before deriving the subscription ID.

func ProtocolError

go
func ProtocolError(e *core.RequestEvent, status int, code deploy.ErrorCode, message string, cause error) error

ProtocolError writes a structured PBVex error response.

func RequestID

go
func RequestID(e *core.RequestEvent) string

RequestID returns a bounded request ID, preferring the X-Request-Id header and falling back to a generated UUID. It strips or rejects unsafe values.

type Broadcaster

Broadcaster manages active realtime subscriptions and broadcasts invalidation events to them using a bounded, coalescing design.

go
type Broadcaster struct {
    // contains filtered or unexported fields
}

func NewBroadcaster

go
func NewBroadcaster(service *deploy.Service, config Config) *Broadcaster

NewBroadcaster creates a new realtime broadcaster.

func (*Broadcaster) Handle

go
func (b *Broadcaster) Handle(e *core.RequestEvent) error

Handle is the POST /api/pbvex/realtime handler (GET is retained as a strictly bounded compatibility fallback).

func (*Broadcaster) InvalidateAll

go
func (b *Broadcaster) InvalidateAll()

InvalidateAll notifies every active subscription to re-run its query. It is non-blocking and coalesces: slow subscriptions receive a single pending notification that will be processed after the current run.

func (*Broadcaster) ReconnectAll

go
func (b *Broadcaster) ReconnectAll()

ReconnectAll closes all active subscription connections so that clients reconnect and re-negotiate event-size limits with the newly active deployment. Called on activation/rollback where the pinned deployment snapshot (and its maxReturnValueBytes) may differ from the new one. The generation is incremented under the write lock so that subscriptions admitted before this call but not yet registered are rejected by subscribeWithFence.

type Config

Config controls realtime behavior.

go
type Config struct {
    PingInterval         time.Duration
    MaxConnections       int
    MaxConnectionsPerIP  int
    MaxConcurrentQueries int
    MaxBodyBytes         int64
    MaxGETArgsBytes      int64
}

func DefaultConfig

go
func DefaultConfig() Config

DefaultConfig returns the default realtime configuration.

type Subscription

Subscription is a single realtime SSE subscription.

go
type Subscription struct {
    // contains filtered or unexported fields
}

Generated by gomarkdoc

Generated API reference. Source of truth is the codebase.