Expand description
Configuration loader for the TxGate signing service.
This module provides utilities for loading, saving, and managing configuration
files from the filesystem. It handles path expansion (e.g., ~ to home directory)
and provides sensible defaults when configuration files don’t exist.
§Default Location
Configuration is stored at ~/.txgate/config.toml by default.
§Examples
§Loading configuration with defaults
use txgate_core::config_loader::load_config;
// Load config from default location, using defaults if file doesn't exist
let config = load_config().expect("failed to load config");§Using ConfigLoader for more control
use txgate_core::config_loader::ConfigLoader;
use std::path::PathBuf;
// Create loader with default base directory (~/.txgate)
let loader = ConfigLoader::new().expect("failed to create loader");
// Check if config exists
if loader.exists() {
let config = loader.load().expect("failed to load config");
println!("Loaded config with timeout: {}s", config.server.timeout_secs);
} else {
// Write default configuration
loader.write_default().expect("failed to write default config");
}§Custom base directory
use txgate_core::config_loader::ConfigLoader;
use std::path::PathBuf;
let loader = ConfigLoader::with_base_dir(PathBuf::from("/custom/txgate"));
let config = loader.load().expect("failed to load config");Structs§
- Config
Loader - Configuration loader that handles reading and writing configuration files.
Functions§
- default_
base_ dir - Returns the default base directory for
TxGatefiles (~/.txgate). - expand_
path - Expands
~in paths to the home directory. - load_
config - Loads configuration from the default location with defaults for missing values.
- load_
config_ with_ expanded_ paths - Loads configuration from the default location and expands all paths.