Documentation
¶
Overview ¶
Package config provides a configuration system for Lakta using koanf. It supports loading configuration from YAML, JSON, and TOML files, environment variables, and CLI flags with hot-reload support.
Index ¶
Constants ¶
const ( CategoryOTel = "otel" CategoryLogging = "logging" CategoryHealth = "health" CategoryHTTP = "http" CategoryGRPC = "grpc" CategoryDB = "db" CategoryWorkflows = "workflows" )
Category constants for module organization.
const DefaultInstanceName = "default"
DefaultInstanceName is the default instance name for modules.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶ added in v0.0.4
Bind creates a module that binds a config struct to a koanf path and registers it in DI as *Binding[T]. Path segments are joined with "." (e.g. "app", "limits" → "app.limits").
func ModulePath ¶
ModulePath generates the config path for a module instance. Example: ModulePath("grpc", "server", "internal") -> "modules.grpc.server.internal"
Types ¶
type Binding ¶ added in v0.0.4
type Binding[T any] struct { // contains filtered or unexported fields }
Binding is a thread-safe, cached config accessor with hot-reload support.
func GetBinding ¶ added in v0.0.4
GetBinding returns the Binding for advanced use (OnChange callbacks).
type Config ¶
type Config struct {
// EnvPrefix specifies the prefix for environment variables used to override configuration values.
EnvPrefix string
// ConfigDirs specifies the directories to search for configuration files in the given order.
ConfigDirs []string
// ConfigName specifies the base name of the configuration file without its file extension.
ConfigName string
// Args contains the command-line arguments to be parsed for configuration overrides.
Args []string
}
Config holds the configuration for the config module.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns default configuration.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module is the configuration module that loads and provides configuration.
func (*Module) Init ¶
Init initializes the config module, loading configuration from files, env vars, and CLI flags.
func (*Module) IsConfigModule ¶
func (m *Module) IsConfigModule()
IsConfigModule is a marker method to identify this module as the config module.
type Option ¶
type Option func(cfg *Config)
Option manipulates Config.
func WithConfigDirs ¶
WithConfigDirs sets directories to search for config files.
func WithConfigName ¶
WithConfigName sets the base config file name without extension (default: "lakta").
func WithEnvPrefix ¶
WithEnvPrefix sets the environment variable prefix (default: "LAKTA_").
type Passthrough ¶ added in v0.0.2
Passthrough captures arbitrary config keys (via koanf's ",remain") and carries the target struct type T for documentation generators to discover via reflect.
type ReloadNotifier ¶ added in v0.0.2
ReloadNotifier can register callbacks for config reload events.
type Validatable ¶ added in v0.0.4
type Validatable interface {
Validate() error
}
Validatable is implemented by config structs that need validation after unmarshalling.