Sign up form and other stuff
[recipes.git] / backend / src / config.rs
1 use std::{fmt, fs::File};
2
3 use ron::de::from_reader;
4 use serde::Deserialize;
5
6 use crate::consts;
7
8 #[derive(Deserialize, Clone)]
9 pub struct Config {
10 pub port: u16,
11 pub smtp_login: String,
12 pub smtp_password: String,
13 }
14
15 // Avoid to print passwords.
16 impl fmt::Debug for Config {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 f.debug_struct("Config")
19 .field("port", &self.port)
20 .field("smtp_login", &self.smtp_login)
21 .field("smtp_password", &"*****")
22 .finish()
23 }
24 }
25
26 pub fn load() -> Config {
27 let f = File::open(consts::FILE_CONF).unwrap_or_else(|_| panic!("Failed to open configuration file {}", consts::FILE_CONF));
28 match from_reader(f) {
29 Ok(c) => c,
30 Err(e) => panic!("Failed to load config: {}", e)
31 }
32 }