From b7a2265e9b29d8fa09f84f5213ef7f8ed3045ca6 Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Wed, 13 Nov 2024 20:00:15 +0000 Subject: initial commit --- src/config.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/config.rs (limited to 'src/config.rs') 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, + files_dir: std::path::PathBuf, + database_connection: String, +} + +impl Config { + pub fn from_file(path: &str) -> Result { + 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 + } +} -- cgit