use serde::Deserialize; use std::path::PathBuf; #[derive(Debug, Deserialize, Clone)] pub struct Config { pub database: DatabaseConfig, pub server: ServerConfig, pub storage: StorageConfig, } #[derive(Debug, Deserialize, Clone)] pub struct DatabaseConfig { pub url: String, } #[derive(Debug, Deserialize, Clone)] pub struct ServerConfig { pub host: String, pub port: u16, } #[derive(Debug, Deserialize, Clone)] pub struct StorageConfig { pub images_dir: PathBuf, pub thumbnails_dir: PathBuf, } impl Config { pub fn load() -> Result { let config = config::Config::builder() .add_source(config::File::with_name("config")) .build()?; config.try_deserialize() } pub fn server_address(&self) -> String { format!("{}:{}", self.server.host, self.server.port) } }