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)]
pub struct Config {
pub scheme: String,
pub port: u16,
pub scheme: Option<String>,
pub port: Option<u16>,
pub mail: Option<String>,
pub lang: Option<String>,
}
@ -20,8 +20,8 @@ pub fn get_config(file_path: &str) -> Config {
// No config file
{
Config {
scheme: "http".to_string(),
port: 8080,
scheme: None,
port: None,
mail: None,
lang: None,
}

View file

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