Documentation
¶
Overview ¶
Package config provides environment and file-based configuration with type-safe accessors.
Index ¶
- func Env(key, def string) string
- func EnvRequired(key string) string
- func Load(cfg *Config, path string) error
- func LoadDir(cfg *Config, dir string) error
- func LoadEnv(path string) error
- func LoadEnvOverride(path string) error
- type Config
- func (c *Config) All() map[string]any
- func (c *Config) Bool(key string, def bool) bool
- func (c *Config) Duration(key string, def time.Duration) time.Duration
- func (c *Config) Get(key string) any
- func (c *Config) GetD(key string, def any) any
- func (c *Config) Int(key string, def int) int
- func (c *Config) Merge(values map[string]any)
- func (c *Config) Set(key string, value any)
- func (c *Config) String(key, def string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvRequired ¶
EnvRequired returns an env variable or panics if absent.
func Load ¶
Load reads a config file (YAML or TOML) and merges it into cfg. The format is inferred from the file extension.
func LoadDir ¶
LoadDir reads all YAML/TOML files in dir and merges them using the filename (without extension) as the top-level key. E.g. config/database.yaml → "database.*".
func LoadEnv ¶
LoadEnv parses a .env file and sets each key=value pair as an environment variable. Existing OS env variables are NOT overwritten (use LoadEnvOverride for that).
func LoadEnvOverride ¶
LoadEnvOverride parses a .env file and overwrites existing OS env variables.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the merged configuration from all sources (env, YAML, TOML, .env files).
func (*Config) Duration ¶
Duration returns the value at key as time.Duration (parsed from string e.g. "5m", "1h").