Documentation
¶
Overview ¶
Package etcd provides a source.Reader implementation that reads scripts from an etcd cluster. It leverages etcd's native Watch API for efficient hot-reload detection without polling.
Construction:
src, err := etcd.New(ctx,
etcd.WithEndpoints("localhost:2379"),
etcd.WithPrefix("scripts/lua/"),
)
Hot-reload uses etcd's built-in Watch mechanism: a watch is established on the key and a signal is sent whenever a PUT or DELETE event occurs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("etcd source: key not found")
ErrNotFound is returned (wrapped) by Load when the requested key does not exist in etcd. Detect with errors.Is(err, ErrNotFound) or the convenience helper IsNotFound.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err represents a "key not found" response from etcd. Equivalent to errors.Is(err, ErrNotFound).
Types ¶
type Option ¶
type Option func(*configOptions)
Option configures a Reader. Pass to New.
func WithEndpoints ¶
WithEndpoints sets the etcd server endpoints (default ["localhost:2379"]).
func WithPassword ¶
WithPassword sets the etcd password for authentication.
func WithPrefix ¶
WithPrefix sets a key prefix that is transparently prepended to every key before it is resolved against etcd. Useful when all scripts share a common namespace (e.g. WithPrefix("scripts/lua/")).
Leading slashes are stripped; no other normalization is applied.
func WithTimeout ¶
WithTimeout sets the etcd client timeout (default 5s).
func WithUsername ¶
WithUsername sets the etcd username for authentication.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads scripts from etcd.
All exported methods are safe for concurrent use. Reader implements the source.ReadWatcher interface.
func New ¶
New creates an etcd-backed Reader. At least one endpoint must be supplied via WithEndpoints (default is "localhost:2379"). All other settings are optional.
Authentication can be enabled via WithUsername / WithPassword.
func (*Reader) Load ¶
Load fetches the value from etcd and returns it as a string. Context cancellation propagates to the underlying request.
An empty response (key not found) is reported as a wrapped ErrNotFound. Other errors are wrapped with the key for easier debugging.
func (*Reader) Watch ¶
Watch returns a channel that signals when the value identified by `key` changes. It uses etcd's native Watch API for efficient event-driven notification without polling.
The returned channel is closed when the context is cancelled. Callers should re-Load the script after receiving from the channel.