use lazy_static::lazy_static; use serde::Deserialize; /* Variables */ const CONFIG_PREFIX: &str = "FJ_PAGES_"; const CONFIG_DEFAULT: &str = r#" [domain] # The domain of the website domain = "*" # The temporary directory for storing files temp_dir = "/tmp" "#; lazy_static! { #[derive(Debug)] pub static ref CONFIG: Config = { // Identify path of the configuration file let path = std::env::var(format!("{}CONFIG_PATH", CONFIG_PREFIX)).unwrap_or("config.toml".to_string()); // Read the configuration file let result_config = std::fs::read_to_string(path) .unwrap_or(CONFIG_DEFAULT.to_string()); // Parse the configuration file toml::from_str(&result_config) .expect("Failed to parse configuration file") }; } /* Structures */ #[derive(Deserialize, Debug, Clone)] pub struct Domain { // Regex is allowed domains: Vec } #[derive(Deserialize, Debug, Clone)] pub struct Config { pub domain: Domain, pub temp_dir: String, pub pages_root: String, }