30 lines
728 B
Rust
30 lines
728 B
Rust
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize, Clone)]
|
|
pub struct Config {
|
|
pub scheme: String,
|
|
pub port: u16,
|
|
pub mail: Option<String>,
|
|
pub lang: Option<String>,
|
|
}
|
|
|
|
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(),
|
|
port: 8080,
|
|
mail: None,
|
|
lang: None,
|
|
}
|
|
}
|
|
}
|
|
}
|