provider

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package provider defines the Provider interface for configuration backends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backoff added in v0.1.14

func Backoff(attempt int) time.Duration

Backoff returns how long to wait before the given reconnect attempt. The attempt is zero-based: attempt 0 waits backoffBase, and each subsequent attempt doubles the wait up to backoffMax. Providers use it to avoid hammering a backend that is temporarily unavailable.

func CommonPrefix added in v0.1.14

func CommonPrefix(keys []string) string

CommonPrefix returns the longest common prefix shared by all the given keys. Providers use it to watch every registered key with a single prefix-scoped operation (an etcd prefix watch, a Redis keyspace subscription, a SQL LIKE query) instead of one operation per key. It returns an empty string when the keys share no common prefix.

func SleepBackoff added in v0.1.14

func SleepBackoff(ctx context.Context, attempt int) bool

SleepBackoff blocks for the backoff duration of the given attempt, returning true once the wait elapses. It returns false immediately if ctx is cancelled during the wait, so callers can use it as their loop's exit signal.

Types

type Provider

type Provider interface {
	// Get retrieves the current raw value for a key from the backend.
	Get(ctx context.Context, key string) (string, error)

	// Watch monitors multiple keys for changes. The provider is free to
	// implement this as a single prefix watch, a batch poll, or any other
	// efficient strategy. When a change is detected for a key, onChange is
	// called with the key and the new raw string value. When a key is removed
	// from the backend, onDelete is called with the key so the SDK can revert
	// it to the DcValue default.
	// The implementation must block until the context is cancelled or an error occurs.
	Watch(ctx context.Context, keys []string, onChange func(key string, value string), onDelete func(key string)) error

	// Close releases any resources held by the provider.
	Close() error
}

Provider is the interface that all config backends must implement. Each provider decides its own strategy for watching changes:

  • etcd: native Watch API with prefix watching (event-driven)
  • Redis/MySQL/PostgreSQL/Vault: batch polling of all keys
  • File: filesystem event notification

Directories

Path Synopsis
Package etcd implements the provider.Provider interface for etcd configuration backends.
Package etcd implements the provider.Provider interface for etcd configuration backends.
Package file implements provider.Provider for local file-based configuration.
Package file implements provider.Provider for local file-based configuration.
Package mysql implements the provider.Provider interface for MySQL configuration backends.
Package mysql implements the provider.Provider interface for MySQL configuration backends.
Package postgresql implements the provider.Provider interface for PostgreSQL configuration backends.
Package postgresql implements the provider.Provider interface for PostgreSQL configuration backends.
Package redis implements the provider.Provider interface for Redis configuration backends.
Package redis implements the provider.Provider interface for Redis configuration backends.
Package vault implements the provider.Provider interface for HashiCorp Vault KV v2 backends.
Package vault implements the provider.Provider interface for HashiCorp Vault KV v2 backends.

Jump to

Keyboard shortcuts

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