fj-pages/src/conf.rs
mrrpnya 7d0e1d2c73
Some checks failed
Run tests / cargo_test (push) Failing after 3m5s
Run tests / cargo_clippy (push) Failing after 3m4s
Run tests / cargo_fmt (push) Failing after 3m3s
initial
2025-02-01 18:58:32 -08:00

44 lines
No EOL
1 KiB
Rust

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<String>
}
#[derive(Deserialize, Debug, Clone)]
pub struct Config {
pub domain: Domain,
pub temp_dir: String,
pub pages_root: String,
}