Documentation
¶
Overview ¶
Package config implements unified configuration handling for dirio.
This allows uniform definition and handling of environment variables, CLI flags, and YAML config file values with consistent precedence rules.
Source Priority ¶
Configuration values are resolved with the following priority (highest to lowest):
- Environment variables (DIRIO_* prefix)
- CLI flags
- Config file (YAML via viper)
- Default values
Usage ¶
Options are defined in options.go using the Option[T] generic type:
var Port = option.NewOption("port", 9000)
The ValueResolver retrieves values respecting priority:
resolver := config.NewValueResolver(cmd.Flags(), nil) port := resolver.GetInt(config.Port)
For typical usage, call LoadConfig during startup:
settings, err := config.LoadConfig(cmd.Flags(), nil)
if err != nil {
return err
}
The global configuration can be accessed from anywhere:
cfg := config.GetConfig() // or, if you expect it to be set: cfg := config.MustGetConfig()
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DataDir specifies the root directory for object storage DataDir = option.NewOption("data-dir", "/data") // Port specifies the HTTP server port Port = option.NewOption("port", 9000) // AccessKey is the root access key for authentication AccessKey = option.NewOption("access-key", "dirio-admin") // SecretKey is the root secret key for authentication SecretKey = option.NewOption("secret-key", "dirio-admin-secret") )
Server configuration options
var ( // LogLevel controls the application log level (debug, info, warn, error) LogLevel = option.NewOption("log-level", "info") // LogFormat controls the log output format (text, json) LogFormat = option.NewOption("log-format", "text") // Verbosity controls component chattiness (quiet, normal, verbose) Verbosity = option.NewOption("verbosity", "normal") // Debug enables debug mode (shortcut for log-level=debug) Debug = option.NewOption("debug", false) )
Logging configuration options
var ( // MDNSEnabled controls whether mDNS service discovery is enabled MDNSEnabled = option.NewOption("mdns-enabled", false) // MDNSName is the mDNS service name to advertise MDNSName = option.NewOption("mdns-name", "dirio-s3") // MDNSHostname is the hostname component for mDNS (defaults to system hostname) // The advertised name will be: {mdns-name}.{mdns-hostname}.local MDNSHostname = option.NewOption("mdns-hostname", "") // MDNSMode controls mDNS responder mode detection // - "auto": Detect via port 5353 probe (default) // - "guest": Force Guest mode (PTR/SRV only, delegates A/AAAA to system) // - "master": Force Master mode (full A/AAAA + PTR/SRV stack) MDNSMode = option.NewOption("mdns-mode", "auto") // CanonicalDomain is the canonical domain for URL generation CanonicalDomain = option.NewOption("canonical-domain", "") // Region is the AWS-style region for the data directory (e.g., us-east-1) // Note: If data config exists, this flag is informational only Region = option.NewOption("region", "us-east-1") )
mDNS and networking options (for future use)
var ( // ConsoleEnabled controls whether the embedded web admin console is served ConsoleEnabled = option.NewOption("console", true) // ConsoleDedicatedPort controls whether the admin console and control plane // are served on their own port (dual-port mode) or share the main S3 port // (single-port mode). Default false = single-port mode. ConsoleDedicatedPort = option.NewOption("console-dedicated-port", false) // ConsolePort is the port used for the admin console and control plane when // ConsoleDedicatedPort is true. Has no effect in single-port mode. ConsolePort = option.NewOption("console-port", 9010) )
Console configuration options
var ( // OTLPMetricsEnabled controls whether metrics are pushed to an OTLP endpoint. OTLPMetricsEnabled = option.NewOption("otlp-metrics-enabled", false) // OTLPMetricsEndpoint is the base URL of the OTLP HTTP metrics receiver. // e.g. "http://localhost:4318" OTLPMetricsEndpoint = option.NewOption("otlp-metrics-endpoint", "http://localhost:4318") // OTLPMetricsInterval is the push interval in seconds. OTLPMetricsInterval = option.NewOption("otlp-metrics-interval", 30) )
Telemetry / OTLP configuration options
var ( // ShutdownTimeout is the number of seconds to allow for graceful shutdown // before connections are forcefully closed. ShutdownTimeout = option.NewOption("shutdown-timeout", 30) )
Lifecycle configuration options
Functions ¶
This section is empty.
Types ¶
type Settings ¶
type Settings struct {
// Server settings
DataDir string
Port int
Region string // CLI region (informational if data config exists)
AccessKey string // CLI admin credentials (coexists with data config credentials)
SecretKey string // CLI admin credentials (coexists with data config credentials)
// Logging settings
LogLevel string
LogFormat string
Verbosity string
Debug bool
// mDNS settings
MDNSEnabled bool
MDNSName string
MDNSHostname string
MDNSMode string
CanonicalDomain string
// Data directory configuration (loaded from .dirio/config.json if exists)
DataConfig *data.ConfigData
// CLICredentialsExplicitlySet tracks whether access_key/secret_key were
// explicitly provided (via env, flag, or config) vs using defaults
CLICredentialsExplicitlySet bool
// CLIRegionExplicitlySet tracks whether region was explicitly provided
CLIRegionExplicitlySet bool
// Console settings
ConsoleEnabled bool
ConsoleDedicatedPort bool
ConsolePort int
// Lifecycle settings
ShutdownTimeout time.Duration
// Telemetry / OTLP settings
OTLPMetricsEnabled bool
OTLPMetricsEndpoint string
OTLPMetricsInterval time.Duration
}
Settings represents all configuration values that dirio relies on to run. These values are resolved from: 1. Environment variables, 2. CLI flags, 3. Config file (YAML)
Note: Some settings (credentials, region) may also come from data directory config (.dirio/config.json) which takes precedence over CLI/app config for those values.
func GetConfig ¶
func GetConfig() *Settings
GetConfig returns the current global configuration. Returns nil if LoadConfig has not been called.
func LoadConfig ¶
LoadConfig creates a Settings struct by resolving values from all sources. This should be called during application startup after viper and flags are initialized.
func MustGetConfig ¶
func MustGetConfig() *Settings
MustGetConfig returns the current global configuration or panics if not loaded.
type ValueResolver ¶
type ValueResolver struct {
// contains filtered or unexported fields
}
ValueResolver handles the resolution of configuration values from multiple sources. Priority order (highest to lowest): Environment -> CLI Flag -> Config File (Viper) -> Default
func NewValueResolver ¶
func NewValueResolver(flagSet *pflag.FlagSet, v *viper.Viper) *ValueResolver
NewValueResolver creates a new resolver with the given flag set and viper instance. If viper is nil, the default viper instance will be used.
func (*ValueResolver) Get ¶
func (vr *ValueResolver) Get(o option.RegisteredOption) string
Get retrieves the value for an option, respecting the source priority. Returns the value as a string.
func (*ValueResolver) GetBool ¶
func (vr *ValueResolver) GetBool(o option.RegisteredOption) bool
GetBool retrieves a boolean value for an option
func (*ValueResolver) GetInt ¶
func (vr *ValueResolver) GetInt(o option.RegisteredOption) int
GetInt retrieves an integer value for an option
func (*ValueResolver) WasExplicitlySet ¶
func (vr *ValueResolver) WasExplicitlySet(o option.RegisteredOption) bool
WasExplicitlySet returns true if the option value was set via env, flag, or config file (i.e., not using the default value)