feat: add declarative Options.Streams for automatic JetStream stream creation
Some checks failed
CI / Build and Test (push) Has been cancelled

Streams listed in Options.Streams are created by Start() when the
embedded NATS server initializes, replacing manual EnsureStream calls
during setup. Migrates nats-chatroom and pubsub-crud examples.
This commit is contained in:
Ryan Hamamura
2026-02-19 12:24:44 -10:00
parent 42b21348cb
commit 60009124c9
6 changed files with 62 additions and 73 deletions

View File

@@ -53,10 +53,15 @@ type Options struct {
// Defaults to "/_datastar.js" if empty.
DatastarPath string
// PubSub enables publish/subscribe messaging. Use vianats.New() for an
// embedded NATS backend, or supply any PubSub implementation.
// PubSub enables publish/subscribe messaging. When nil, an embedded NATS
// server starts automatically in Start(). Supply any PubSub implementation
// to replace it.
PubSub PubSub
// Streams declares JetStream streams to create when Start() initializes
// the embedded NATS server. Ignored when a custom PubSub is configured.
Streams []StreamConfig
// ContextSuspendAfter is the time a context may be disconnected before
// the reaper suspends it (frees page resources but keeps the context
// shell for seamless re-init on reconnect). Default: 15m.