X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Fconfig.rs;fp=backend%2Fsrc%2Fconfig.rs;h=393a03bfcde41a6f1bbf81c5c145771c74fd6abb;hp=0000000000000000000000000000000000000000;hb=45d4867cb37ce8d7007c4d98de70d81d0b705b92;hpb=b1ffd1a04a55d6653ed55ea99f09550e5a8a9a96 diff --git a/backend/src/config.rs b/backend/src/config.rs new file mode 100644 index 0000000..393a03b --- /dev/null +++ b/backend/src/config.rs @@ -0,0 +1,32 @@ +use std::{fmt, fs::File}; + +use ron::de::from_reader; +use serde::Deserialize; + +use crate::consts; + +#[derive(Deserialize, Clone)] +pub struct Config { + pub port: u16, + pub smtp_login: String, + pub smtp_password: String, +} + +// Avoid to print passwords. +impl fmt::Debug for Config { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Config") + .field("port", &self.port) + .field("smtp_login", &self.smtp_login) + .field("smtp_password", &"*****") + .finish() + } +} + +pub fn load() -> Config { + let f = File::open(consts::FILE_CONF).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF)); + match from_reader(f) { + Ok(c) => c, + Err(e) => panic!("Failed to load config: {}", e) + } +} \ No newline at end of file