Documentation
¶
Overview ¶
Package source provides a composable configuration source system. Sources are checked in priority order; the first hit wins.
Index ¶
- Variables
- type Chain
- type Database
- type DatabaseOption
- type Env
- type Memory
- func (m *Memory) Close() error
- func (m *Memory) Get(_ context.Context, key string) (*Value, error)
- func (m *Memory) List(_ context.Context, prefix string) ([]*Value, error)
- func (m *Memory) Name() string
- func (m *Memory) Set(ctx context.Context, key, raw string)
- func (m *Memory) Watch(_ context.Context, key string, fn WatchFunc) error
- type Source
- type Value
- type WatchFunc
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = errors.New("source: key not found")
ErrKeyNotFound is returned when no source contains the requested key.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a priority-ordered list of Sources. Get returns the first hit.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database reads configuration from a config.Store backend.
func NewDatabase ¶
func NewDatabase(store config.Store, appID string, opts ...DatabaseOption) *Database
NewDatabase creates a Database source backed by the given config store.
type DatabaseOption ¶
type DatabaseOption func(*Database)
DatabaseOption configures a Database source.
func WithMetrics ¶
func WithMetrics(m gometrics.Metrics) DatabaseOption
WithMetrics counts the source's watch polls on m by result: changed, unchanged or error. A failed read is otherwise silent: the poll skips the key until the next tick. A nil m records nothing.
func WithPollInterval ¶
func WithPollInterval(d time.Duration) DatabaseOption
WithPollInterval sets the polling interval for watch. Default is 30 seconds.
type Env ¶
type Env struct {
// contains filtered or unexported fields
}
Env reads configuration from environment variables.
func NewEnv ¶
NewEnv creates an Env source. If prefix is non-empty, keys are looked up as PREFIX_KEY (uppercased, dashes replaced with underscores).
func (*Env) Get ¶
Get reads the key from os.Getenv. Keys are normalized: uppercased, dashes → underscores.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is an in-memory source useful for testing and dynamic overrides.
type Source ¶
type Source interface {
// Name returns a human-readable name for this source.
Name() string
// Get retrieves a value by key.
Get(ctx context.Context, key string) (*Value, error)
// List returns all values matching a prefix (empty prefix = all).
List(ctx context.Context, prefix string) ([]*Value, error)
// Watch registers a callback for changes to a key. It blocks until ctx is done.
// Sources that don't support watching should return nil immediately.
Watch(ctx context.Context, key string, fn WatchFunc) error
// Close releases any resources held by the source.
Close() error
}
Source is a configuration value provider.
type Value ¶
type Value struct {
Key string `json:"key"`
Raw string `json:"raw"`
Source string `json:"source"`
Version int64 `json:"version,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
}
Value represents a configuration value from a source.