Skip to content

ServerSettings

Constructs an embedded NATS server. Every field has an equivalent in nats-server's own options, because an embedded server is the same server — see why that is not a compromise.

Field Type Default Status at v0.1.0
InProcessOnly bool false Must be true
Host string "" Refused if set
Port int 0 Refused if set
Routes []string nil Refused if set
ClusterName string "" Refused if set
ClusterPort int 0 Refused if set
JetStream bool false Supported
StoreDir string "" Required when JetStream is set
MaxMemory int64 0 Zero takes the server's own default
MaxStore int64 0 Zero takes the server's own default
ReadyTimeout time.Duration 10s How long Start waits

The refusals

Five fields are refused rather than ignored, with ErrNetworkModeUnsupported.

This module has no TLS or authentication configuration, so a listening server would accept any connection that could reach it — no credential, nothing encrypted, and a token supplied by a client neither required by the server nor protected in transit.

Refusing rather than ignoring matters: a configuration that sets Port gets an error rather than an in-process server it did not ask for and cannot reach.

The fields remain in the struct because the design is not being abandoned, only deferred. When TLS and authentication arrive they become supported, which is additive.

When network mode returns, Port: 0 will not mean what you expect

nats-server reads port zero as DEFAULT_PORT — 4222 — not "ask the operating system". Its ephemeral sentinel is RANDOM_PORT, which is -1 (opts.go:6007, const.go:78-83).

This is recorded because the first draft of this module documented the opposite, and a test that bound port zero passed only because 4222 happened to be free.

InProcessOnly

Maps to DontListen. There is no socket, so nothing outside the process can reach the server whatever the network allows — a security property as much as a performance one.

Clients reach it through client.InProcess, which takes an in-memory net.Conn from the server rather than dialling.

ClientURL() always returns empty, because every server this package builds is in-process and reporting an address that cannot be reached would be worse than reporting none.

ReadyTimeout

Start blocks until the server accepts connections or this elapses, then returns ErrNotReady.

Blocking is the point. A server that never becomes ready fails at startup, where an operator is watching, rather than at the first publish — which might be hours later, and will be blamed on the publisher.

The server's own error is currently lost

The embedded server is not yet connected to the slog.Logger passed to Start, so a failure it could have explained — an unusable JetStream directory, for instance — surfaces as a generic ten-second readiness timeout instead. Tracked.

What is deliberately not here

NoSigs is set unconditionally and is not a setting. go/controls owns signal handling for the process, and a broker that also traps signals produces a shutdown where neither party is in charge.

Gateways, leaf nodes and account configuration are not exposed. They are fields on the same underlying options struct, reachable through Server.Raw(), and a second caller reaching for the same one is a request for it to become a setting.