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 (*Registry) Add ¶
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 ¶
Close runs every entry's closers and returns the joined error. The registry is unusable afterwards.
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.