etcd

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package etcd implements the provider.Provider interface for etcd configuration backends. It uses etcd's native Watch API with prefix-based watching for efficient event-driven dynamic configuration updates. A single watch call monitors all keys under a common prefix.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements the poya Provider interface using etcd's native Watch API.

func New

func New(client *clientv3.Client) *Provider

New creates an etcd provider from a fully-configured etcd client. The caller owns the client and configures every connection option (endpoints, TLS, auth, dial timeout, etc.) directly on clientv3. The provider does not close the client; call clientv3.Client.Close yourself when done, or use Provider.Close which delegates to it.

func (*Provider) Close

func (p *Provider) Close() error

Close disconnects from etcd.

func (*Provider) Get

func (p *Provider) Get(ctx context.Context, key string) (string, error)

Get retrieves the current value for a key from etcd.

func (*Provider) Watch

func (p *Provider) Watch(ctx context.Context, keys []string, onChange func(key string, value string)) error

Watch monitors all keys under a common prefix using a single etcd Watch call. It extracts the longest common prefix from the provided keys, watches that prefix, and calls onChange for each key that changes. If the watch is dropped (compaction, a broken connection, the channel closing) it re-reads the current values and re-establishes the watch with exponential backoff, returning only when the context is cancelled.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL