Envig is a lightweight and flexible configuration
and environment manager for V.
It unifies configuration loading from TOML files and environment variables,
and supports dynamic expansion like dotenv-expand
.
β
Load configuration from TOML files dynamically
β
Support for environment variables via .env
files
β
Dynamic variable expansion (${VAR_NAME}
style)
β
Load from directories, single files, or raw text
β
Fallback and default values for missing keys
β
Type-safe retrieval with automatic conversion
β
Lightweight and fast, designed specifically for the V language
Install it via VPM:
v install siguici.envig
Or add it to your dependencies:
import siguici.envig
import siguici.envig
mut config := envig.ConfigManager.load()
println(config.value('database.host'))
import siguici.envig
mut config := envig.ConfigManager.load(
file: 'config.toml'
dir: 'config'
)
println(config.value('database.host'))
import siguici.envig
mut config := envig.Config.new('config.toml')
println(config.value('database.host'))
mut config := envig.Config.new('config')
println(config.value('app.debug'))
toml_text := """
[database]
host = "localhost"
port = 5432
"""
mut config := envig.Config.new(toml_text)
println(config.value('database.port')) // 5432
import siguici.envig
mut env := envig.Env.load('.env')
println(env.get('APP_ENV'))
# .env
APP_ENV=production
DB_URL="postgres://user:password@localhost:5432/${APP_ENV}"
mut env := envig.Env.load('.env').expand()
println(env.get('DB_URL')) // "postgres://user:password@localhost:5432/production"
Envig provides a powerful unified interface combining environment and configuration:
mut e := envig.envig()
port := e.env_or_default('PORT', '8080')
db_url := e.get('database.url')
debug := e.get_as[bool]('app.debug')
println('Server running on port $port')
println('Database URL: $db_url')
println('Debug mode: $debug')
Or specify custom options:
mut e := envig.envig(envig.EnvigOptions{
dir: 'settings',
file: 'app.toml',
env: 'production',
})
Purpose | Example |
---|---|
Get environment variable | val := e.env('PORT') |
Get environment with default | val := e.env_or_default('PORT', '3000') |
Get config value (toml.Any) | cfg := e.config('database.url') |
Config with default fallback | cfg := e.config_or_default('db', 'localhost') |
Expand variables in a string | expanded := e.expand('${DATABASE_URL}') |
Unified get (config + expansion) | val := e.get('database.url') |
Unified get with default fallback | val := e.get_or_default('service.url', 'https://default') |
Get as a specific type | debug := e.get_as[bool]('app.debug') |
Method | Description |
---|---|
Config.new(raw string) | Creates a config from raw text or TOML file (panics on error). |
Config.new_opt(raw string) !Config | Optional version returning error instead of panic. |
ConfigManager.new(opts ConfigOptions) | Creates a config manager with options (dir, file). |
ConfigManager.load(opts ConfigOptions) | Loads configuration from file, directory or raw text. |
ConfigManager.load_dir(path string) | Loads all TOML files in a directory. |
ConfigManager.load_file(path string) | Loads a single TOML file. |
ConfigManager.load_text(text string) | Loads config from raw TOML text. |
ConfigManager.value(path string) | Retrieves a value by key (supports nested keys like config.key). |
ConfigManager.value_or_default(key string, default toml.Any) | Retrieves a value or returns a default. |
Method | Description |
---|---|
Env.new(options EnvOptions) | Creates an environment with a map of variables. |
Env.set(key, value) | Sets an environment variable. |
Env.get(key) | Retrieves a variable (returns empty if missing). |
Env.get_or_default(key, default) | Retrieves a variable or returns default. |
Env.apply() | Applies all variables to the OS environment. |
Dotenv.load(options DotenvOptions) | Loads a .env file (appends .APP_ENV if defined). |
Dotenv.load_multiple(files []string) | Loads multiple .env files. |
Dotenv.expand() | Expands variables inside other variables (e.g. ${VAR}). |
Method | Description |
---|---|
new(options EnvigOptions) |
Initialize a new Envig instance |
config(path string) |
Get a configuration value (toml.Any ) |
env(name string) |
Get an environment variable |
get(key string) |
Get config with expansion |
value(key string) |
Get as toml.Any |
get_as[T](key string) |
Type-safe retrieval (T can be int , bool , etc.) |
config_or_default(path, default) |
Config value or fallback |
env_or_default(name, default) |
Env variable or fallback |
expand(value toml.Any) |
Expand variable references |
get_or_default(key, default) |
Unified get with default |
- Support for JSON and YAML configuration formats
- CLI tool for managing environment variables
- Integration with logging and debugging tools
Feel free to submit issues, ideas, or pull requests! Letβs build something great together.
Envig is released under the MIT License.
If you like Envig, give it a β on GitHub!
Enjoy seamless configuration management with Envig! π