diff options
author | 2024-11-13 20:00:15 +0000 | |
---|---|---|
committer | 2024-11-13 20:00:15 +0000 | |
commit | b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6 (patch) | |
tree | 280a31f5887aafdaa200a2b5f4c05ff106d9e365 /src/config.rs | |
download | critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.tar.gz critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.tar.bz2 critch-b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6.zip |
initial commit
Diffstat (limited to '')
-rw-r--r-- | src/config.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..eee2fc2 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,43 @@ +use std::{ + fs::File, + io::Read, + path::{Path, PathBuf}, +}; + +use serde::Deserialize; + +use crate::Result; + +#[derive(Deserialize, Clone)] +pub struct Config { + admin_password: String, + site_password: Option<String>, + files_dir: std::path::PathBuf, + database_connection: String, +} + +impl Config { + pub fn from_file(path: &str) -> Result<Self> { + let path = PathBuf::from(path); + let mut config = String::new(); + File::open(path)?.read_to_string(&mut config)?; + let config: Config = toml::from_str(&config)?; + Ok(config) + } + + pub fn admin_password(&self) -> &str { + &self.admin_password + } + + pub fn site_password(&self) -> Option<&str> { + self.site_password.as_deref() + } + + pub fn files_dir(&self) -> &Path { + self.files_dir.as_path() + } + + pub fn database_connection(&self) -> &str { + &self.database_connection + } +} |