all the config is optional

This commit is contained in:
Mylloon 2023-02-09 11:36:22 +01:00
parent 00cd6405ea
commit d57231cfc4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 12 additions and 6 deletions

View file

@ -2,8 +2,8 @@ use serde::Deserialize;
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
pub struct Config { pub struct Config {
pub scheme: String, pub scheme: Option<String>,
pub port: u16, pub port: Option<u16>,
pub mail: Option<String>, pub mail: Option<String>,
pub lang: Option<String>, pub lang: Option<String>,
} }
@ -20,8 +20,8 @@ pub fn get_config(file_path: &str) -> Config {
// No config file // No config file
{ {
Config { Config {
scheme: "http".to_string(), scheme: None,
port: 8080, port: None,
mail: None, mail: None,
lang: None, lang: None,
} }

View file

@ -31,8 +31,14 @@ mod portfolio;
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
let config = config::get_config("/config/config.toml"); let config = config::get_config("/config/config.toml");
let addr = ("127.0.0.1", config.port); let addr = ("127.0.0.1", config.port.unwrap_or(8080));
println!("Listening to {}://{}:{}", config.scheme, addr.0, addr.1);
println!(
"Listening to {}://{}:{}",
config.clone().scheme.unwrap_or("http".to_string()),
addr.0,
addr.1
);
let static_folder = "static"; let static_folder = "static";
let dist_folder = format!("dist/{static_folder}"); let dist_folder = format!("dist/{static_folder}");