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 ¶
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.
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 ¶
WithConfigPaths overrides the directories searched for application.yaml.
func WithDefaults ¶
WithDefaults configures fallback values applied before YAML and env values.
func WithEnvPrefix ¶
WithEnvPrefix configures an optional environment variable prefix.
func WithProfiles ¶
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.