config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package config provides YAML and ENV configuration loading with priority chain ENV > profile YAML > application.yaml > DEFAULT for the Helix framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotFound = errors.New("helix: config not found")
	ErrInvalidConfig  = errors.New("helix: invalid config")
)

Sentinel errors returned by the configuration loader.

Functions

This section is empty.

Types

type Loader

type Loader interface {
	Load(target any) error
	Lookup(key string) (any, bool)
	ConfigFileUsed() string
	AllSettings() map[string]any
	ActiveProfiles() []string
}

Loader loads application configuration and exposes resolved values by key.

func NewLoader

func NewLoader(opts ...Option) Loader

NewLoader creates a Viper-backed configuration loader.

type Option

type Option func(*loader)

Option configures a Loader.

func WithAllowMissingConfig

func WithAllowMissingConfig() Option

WithAllowMissingConfig lets Load continue when application.yaml is absent. Profile files, defaults, and environment variables can still provide values.

func WithConfigPaths

func WithConfigPaths(paths ...string) Option

WithConfigPaths overrides the directories searched for application.yaml.

func WithDefaults

func WithDefaults(values map[string]any) Option

WithDefaults configures fallback values applied before YAML and env values.

func WithEnvPrefix

func WithEnvPrefix(prefix string) Option

WithEnvPrefix configures an optional environment variable prefix.

func WithProfiles

func WithProfiles(profiles ...string) Option

WithProfiles configures explicit profile YAML files to merge after application.yaml.

type ReloadOption

type ReloadOption func(*reloader) error

ReloadOption configures a Reloader.

func WithReloadInterval

func WithReloadInterval(interval time.Duration) ReloadOption

WithReloadInterval configures the polling interval. Non-positive intervals disable polling.

func WithReloadLogger

func WithReloadLogger(logger *slog.Logger) ReloadOption

WithReloadLogger configures the logger used for background reload errors.

func WithReloadables

func WithReloadables(reloadables ...Reloadable) ReloadOption

WithReloadables registers callbacks invoked after each successful reload.

type Reloadable

type Reloadable interface {
	OnConfigReload()
}

Reloadable is implemented by components that need to react after a successful configuration reload.

type Reloader

type Reloader interface {
	Reload() error
	Start(ctx context.Context) error
	// RLock acquires a shared read lock. Hold it while reading the config target
	// to prevent races with a concurrent background reload.
	RLock()
	// RUnlock releases the read lock acquired by RLock.
	RUnlock()
}

Reloader reloads configuration on demand or from explicit background triggers. Callers must hold RLock while reading the decoded config struct to avoid data races with concurrent background reloads.

func NewReloader

func NewReloader(loader Loader, target any, opts ...ReloadOption) (Reloader, error)

NewReloader creates an opt-in configuration reloader.

Jump to

Keyboard shortcuts

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