config - Configuration Management
Overview
The config module provides configuration file loading with support for multiple formats including JSON, YAML, TOML, INI, HCL, and more.
Supported Formats
- JSON -
.json,.json5 - YAML -
.yaml,.yml - TOML -
.toml - INI -
.ini - HCL -
.hcl - XML -
.xml - Properties -
.properties - ENV -
.env
Core Functions
LoadConfig()
Load configuration file with validation.
Parameters:
c- Config struct pointerpaths- Optional list of file paths to search
Returns:
- Error if loading or validation fails
Search Order:
- Explicit paths provided
- Environment variable
LAZYGOPHERS_CONFIG - Current directory (
conf.*orconfig.*) - Executable directory (
conf.*orconfig.*)
Example:
LoadConfigSkipValidate()
Load configuration file without validation.
Parameters:
c- Config struct pointerpaths- Optional list of file paths to search
Returns:
- Error if loading fails
Example:
SetConfig()
Save configuration to file.
Parameters:
c- Config struct to save
Returns:
- Error if saving fails
Example:
RegisterParser()
Register custom parser for file extension.
Parameters:
ext- File extension (e.g., ".custom")m- Marshaler functionu- Unmarshaler function
Example:
Usage Patterns
Multi-Format Support
Environment-Based Loading
Nested Configuration
Configuration Validation
Best Practices
Default Values
Error Handling
Configuration Hot Reload
Related Documentation
- validator - Data validation
- defaults - Default values
- json - JSON processing
- API Documentation
- Module Overview