mylloon.fr/src/config.rs

31 lines
728 B
Rust
Raw Normal View History

2023-02-08 20:49:05 +01:00
use serde::Deserialize;
2023-02-08 22:14:57 +01:00
#[derive(Deserialize, Clone)]
2023-02-08 20:49:05 +01:00
pub struct Config {
pub scheme: String,
2023-02-08 20:58:24 +01:00
pub port: u16,
2023-02-08 22:14:57 +01:00
pub mail: Option<String>,
pub lang: Option<String>,
2023-02-08 20:49:05 +01:00
}
pub fn get_config(file_path: &str) -> Config {
match std::fs::read_to_string(file_path) {
Ok(file) => match toml::from_str(&file) {
Ok(stored_config) => stored_config,
Err(file_error) => {
panic!("Error in config file: {file_error}");
}
},
Err(_) =>
// No config file
{
Config {
scheme: "http".to_string(),
2023-02-08 20:58:24 +01:00
port: 8080,
2023-02-08 22:14:57 +01:00
mail: None,
lang: None,
2023-02-08 20:49:05 +01:00
}
}
}
}