provider

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package provider abstracts external configuration sources (env, CLI, KV, Vault, ...). Providers are second-class citizens of the reload pipeline: their output is merged into the same map[string]any that file discovery produces, after which the merged document is decoded into the user's strongly-typed *T.

The Provider/Event interface itself lives in fastconf/contracts; this package re-exports it (see aliases.go) and ships the built-in Env/CLI/ File implementations.

Index

Constants

View Source
const (
	PriorityStatic  = contracts.PriorityStatic
	PriorityOverlay = contracts.PriorityOverlay
	PriorityKV      = contracts.PriorityKV
	PriorityK8s     = contracts.PriorityK8s
	PriorityEnv     = contracts.PriorityEnv
	PriorityCLI     = contracts.PriorityCLI
)

Re-exported priority constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLIProvider

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

CLIProvider exposes a pre-parsed map (typically built by the user from command-line flags) as the highest-priority static provider. Users wire it up in main() after their flag parsing completes — fastconf does not own the flag set.

func NewCLI

func NewCLI(data map[string]any) *CLIProvider

NewCLI wraps a map as the CLI layer.

func (*CLIProvider) Load

func (p *CLIProvider) Load(_ context.Context) (map[string]any, error)

Load implements Provider.

func (*CLIProvider) Name

func (p *CLIProvider) Name() string

Name implements Provider.

func (*CLIProvider) Priority

func (p *CLIProvider) Priority() int

Priority implements Provider.

func (*CLIProvider) Watch

func (p *CLIProvider) Watch(_ context.Context) (<-chan Event, error)

Watch implements Provider. CLI is fundamentally static for the process lifetime.

func (*CLIProvider) WithPriority

func (p *CLIProvider) WithPriority(prio int) *CLIProvider

WithPriority overrides the default priority.

type EnvProvider

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

EnvProvider reads process environment variables matching a prefix and translates them into a nested map. Conventions:

  • Prefix is stripped.
  • "__" (double underscore) introduces a nesting level. Single underscore is preserved as part of the key (handles names like APP_FEATURE_FLAGS).
  • Keys are lower-cased.
  • Values are coerced to bool / int64 / float64 / string in that order.

Example: APP_DATABASE__POOL=20 with prefix "APP_" produces {"database":{"pool":int64(20)}}.

func NewEnv

func NewEnv(prefix string) *EnvProvider

NewEnv builds an EnvProvider with the given prefix (e.g. "APP_") and the default Env priority.

func (*EnvProvider) Load

func (p *EnvProvider) Load(_ context.Context) (map[string]any, error)

Load implements Provider.

func (*EnvProvider) Name

func (p *EnvProvider) Name() string

Name implements Provider.

func (*EnvProvider) Priority

func (p *EnvProvider) Priority() int

Priority implements Provider.

func (*EnvProvider) Watch

func (p *EnvProvider) Watch(_ context.Context) (<-chan Event, error)

Watch implements Provider. Env is not watched.

func (*EnvProvider) WithPriority

func (p *EnvProvider) WithPriority(prio int) *EnvProvider

WithPriority overrides the default priority.

type Event

type Event = contracts.Event

Re-exported interface and event aliases.

type FileProvider

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

FileProvider loads a single auxiliary file (yaml/json) outside the main conf.d/ tree — useful for site-specific overrides like /etc/myapp/override.yaml.

func NewFile

func NewFile(path string, priority int) *FileProvider

NewFile builds a FileProvider. Codec is inferred from the file extension.

func (*FileProvider) Load

func (p *FileProvider) Load(_ context.Context) (map[string]any, error)

Load implements Provider.

func (*FileProvider) Name

func (p *FileProvider) Name() string

Name implements Provider.

func (*FileProvider) Priority

func (p *FileProvider) Priority() int

Priority implements Provider.

func (*FileProvider) Watch

func (p *FileProvider) Watch(_ context.Context) (<-chan Event, error)

Watch implements Provider. File watching is handled by the dedicated Watcher subsystem rather than the provider abstraction.

type Provider

type Provider = contracts.Provider

Re-exported interface and event aliases.

Jump to

Keyboard shortcuts

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