Documentation
¶
Overview ¶
Package consul resolves gostructor fields from a HashiCorp Consul KV prefix. Each field maps to a key under the prefix; the key is the field's per-source override (`cfg:"host,consul:database/host"`) or, lacking one, its base name.
It implements gostructor.Watchable using Consul blocking queries: a single long-poll on the prefix returns as soon as any key under it changes, so a reload fires promptly without busy polling. An optional snapshot store (gostructor/snapshot) keeps the last-known-good KV set so the app still starts when Consul is unreachable.
Index ¶
Constants ¶
const DefaultName = "consul"
DefaultName is this source's identity and cfg per-source override key.
const DefaultWaitTime = 5 * time.Minute
DefaultWaitTime bounds a single blocking query; Consul returns earlier the moment a key changes. It also caps how long Watch takes to notice its context was cancelled between queries.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Address is the Consul HTTP address (host:port). Empty uses the api
// defaults (CONSUL_HTTP_ADDR, else 127.0.0.1:8500).
Address string
// Prefix is the KV path fields are read from, e.g. "config/orders". A field
// key is joined onto it with "/".
Prefix string
// Token is the optional ACL token (empty uses CONSUL_HTTP_TOKEN if set).
Token string
// Datacenter optionally targets a non-default datacenter.
Datacenter string
// WaitTime bounds one blocking query; zero uses DefaultWaitTime.
WaitTime time.Duration
// Snapshot, if set, stores each good KV read and is served when Consul is
// unreachable at startup.
Snapshot snapshot.Store
// Name overrides the source identity (DefaultName otherwise).
Name string
// Logger receives watch/fallback diagnostics; nil discards them.
Logger *slog.Logger
}
Options configures a consul Source.