63 lines
1.8 KiB
Rust
63 lines
1.8 KiB
Rust
|
|
//! Platform Config - Unified configuration loading for platform services
|
||
|
|
//!
|
||
|
|
//! This crate provides a unified interface for loading service configurations
|
||
|
|
//! from both Nickel (NCL) and TOML sources, with a hierarchical loading
|
||
|
|
//! strategy.
|
||
|
|
//!
|
||
|
|
//! # Features
|
||
|
|
//!
|
||
|
|
//! - **Dual Format Support**: Load configurations from `.ncl` (Nickel) or
|
||
|
|
//! `.toml` files
|
||
|
|
//! - **Hierarchical Loading**: Environment variables → File-based → Defaults
|
||
|
|
//! - **JSON Intermediate**: All configs converted to JSON for consistent
|
||
|
|
//! processing
|
||
|
|
//! - **Environment Overrides**: Service-specific env var overrides
|
||
|
|
//! - **Error Handling**: Rich, actionable error types
|
||
|
|
//!
|
||
|
|
//! # Usage
|
||
|
|
//!
|
||
|
|
//! Implement the `ConfigLoader` trait for your config struct:
|
||
|
|
//!
|
||
|
|
//! ```ignore
|
||
|
|
//! use platform_config::ConfigLoader;
|
||
|
|
//! use serde::{Deserialize, Serialize};
|
||
|
|
//!
|
||
|
|
//! #[derive(Debug, Default, Serialize, Deserialize)]
|
||
|
|
//! pub struct MyServiceConfig {
|
||
|
|
//! pub server: ServerConfig,
|
||
|
|
//! pub database: DatabaseConfig,
|
||
|
|
//! }
|
||
|
|
//!
|
||
|
|
//! impl ConfigLoader for MyServiceConfig {
|
||
|
|
//! fn service_name() -> &'static str {
|
||
|
|
//! "my-service"
|
||
|
|
//! }
|
||
|
|
//!
|
||
|
|
//! fn load_from_hierarchy() -> Result<Self> {
|
||
|
|
//! // Use default hierarchy: env vars -> files -> defaults
|
||
|
|
//! Ok(Self::default())
|
||
|
|
//! }
|
||
|
|
//!
|
||
|
|
//! fn apply_env_overrides(&mut self) -> Result<()> {
|
||
|
|
//! // Apply service-specific overrides
|
||
|
|
//! Ok(())
|
||
|
|
//! }
|
||
|
|
//! }
|
||
|
|
//!
|
||
|
|
//! // Load config
|
||
|
|
//! let config = MyServiceConfig::load()?;
|
||
|
|
//! ```
|
||
|
|
|
||
|
|
pub mod error;
|
||
|
|
pub mod format;
|
||
|
|
pub mod hierarchy;
|
||
|
|
pub mod loader;
|
||
|
|
pub mod nickel;
|
||
|
|
|
||
|
|
// Re-export main types
|
||
|
|
pub use error::{ConfigError, Result};
|
||
|
|
pub use format::ConfigLoader;
|
||
|
|
pub use hierarchy::{config_base_path, find_config_file, resolve_config_path};
|
||
|
|
pub use loader::{ConfigLoaderExt, ConfigValidator};
|
||
|
|
pub use nickel::is_nickel_available;
|