registry

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package registry holds the set of repositories served by the stackit server, keyed by a stable repoID. Each entry owns the per-repository engine, GitHub client, event broadcaster, and ref watcher — so multiple repositories can be served from one process without leaking events between them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster fans out SSE messages to subscribed clients. Each RepoEntry owns one so events stay scoped to a single repo — a client subscribed to /repos/A/events never receives B's refresh notifications.

func NewBroadcaster

func NewBroadcaster() *Broadcaster

NewBroadcaster creates a new event broadcaster.

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(event, data string)

Broadcast sends an SSE event to every subscribed client. Slow clients drop the message rather than blocking the broadcast.

func (*Broadcaster) Close

func (b *Broadcaster) Close()

Close notifies all subscribers to exit and prevents future broadcasts. It closes every active client channel so SSE handlers blocked on a receive unblock immediately. Safe to call multiple times.

func (*Broadcaster) Done

func (b *Broadcaster) Done() <-chan struct{}

Done returns a channel that closes when the broadcaster is shutting down. SSE handlers select on this to exit promptly during server shutdown.

func (*Broadcaster) Subscribe

func (b *Broadcaster) Subscribe() (chan string, bool)

Subscribe returns a buffered channel that receives every broadcast message until Unsubscribe is called or the broadcaster is closed. The bool is false when the broadcaster is already shut down.

func (*Broadcaster) Unsubscribe

func (b *Broadcaster) Unsubscribe(ch chan string)

Unsubscribe removes ch from the broadcast set and closes it. Safe to call from a defer even if ch was already removed (e.g. by Close).

type EntryConfig

type EntryConfig struct {
	ID          string
	DisplayName string
	RepoRoot    string
	Remote      string
	Engine      engine.Engine
	GitHub      github.Client
}

EntryConfig is the input to NewEntry. It captures the per-repo state the constructor needs to wire up the broadcaster + watcher.

type Registry

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

Registry is a goroutine-safe collection of RepoEntries keyed by ID.

func New

func New() *Registry

New returns an empty registry.

func (*Registry) Add

func (r *Registry) Add(e *RepoEntry) error

Add inserts an entry. The entry's ID must be non-empty, match the allowed pattern, and be unique within the registry.

func (*Registry) Close

func (r *Registry) Close() error

Close runs every entry's closers and returns the joined error. The registry is unusable afterwards.

func (*Registry) Get

func (r *Registry) Get(id string) (*RepoEntry, bool)

Get returns the entry for id. The bool is false when no such entry exists, matching the comma-ok idiom of map access.

func (*Registry) Len

func (r *Registry) Len() int

Len reports the number of registered entries.

func (*Registry) List

func (r *Registry) List() []*RepoEntry

List returns every entry sorted by ID so callers (and tests) get a stable ordering for serialization.

type RepoEntry

type RepoEntry struct {
	ID          string
	DisplayName string
	RepoRoot    string
	Remote      string
	Engine      engine.Engine
	GitHub      github.Client

	Broadcaster *Broadcaster
	Watcher     *watcher.RefWatcher
	// contains filtered or unexported fields
}

RepoEntry is the per-repository state required to serve API requests for one repo. Constructed via NewEntry so the watcher + broadcaster lifecycle stays consistent across call sites; raw struct literals are still usable in tests where neither is needed.

func NewEntry

func NewEntry(cfg EntryConfig) *RepoEntry

NewEntry constructs a ready-to-use entry with a broadcaster, a ref watcher (when RepoRoot is set), and closers that cleanly tear down both when registry.Close is called. The watcher goroutine starts immediately.

func (*RepoEntry) AddCloser

func (e *RepoEntry) AddCloser(fn func() error)

AddCloser registers a teardown function that Registry.Close will invoke in reverse-registration order. Use it to attach lifecycle hooks (logger closers, etc.) when constructing an entry.

Jump to

Keyboard shortcuts

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