From 660ab98dd07d67dafa2b8dbea8651600dc6baf67 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 7 Aug 2021 17:24:25 +0200 Subject: [PATCH] Fix issues with modifying the listen address Signed-off-by: trivernis --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 +- src/main.rs | 7 ++++++- src/utils/settings.rs | 14 ++++++-------- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 687c6aa..f2de0b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -606,7 +606,7 @@ dependencies = [ [[package]] name = "multihook" -version = "0.1.0" +version = "0.1.1" dependencies = [ "chrono", "colored", diff --git a/Cargo.toml b/Cargo.toml index 627af63..2658c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "A webhook server" authors = ["trivernis "] license = "GPL-3.0" readme = "README.md" -version = "0.1.0" +version = "0.1.1" edition = "2018" repository = "https://github.com/Trivernis/multihook.git" diff --git a/README.md b/README.md index 3d0f7df..517771b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ multihook The config allows you to configure actions for each endpoint. The config is most likely stored in `~/.config/multihook` and on Windows maybe in the APPDATA directory (?). -After running the program for the first time there should be a `default-config.toml` file. +After running the program for the first time the config directory and config file should be created. ```toml [server] diff --git a/src/main.rs b/src/main.rs index a4cd13b..5f5a2bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,5 +36,10 @@ async fn init_and_start() { server.add_hook(endpoint.path.clone(), endpoint.into()) } - server.start(&settings.server.address).await + let address = settings + .server + .address + .clone() + .unwrap_or(String::from("127.0.0.1:8080")); + server.start(&address).await } diff --git a/src/utils/settings.rs b/src/utils/settings.rs index dcf4e1e..c2dbae8 100644 --- a/src/utils/settings.rs +++ b/src/utils/settings.rs @@ -14,7 +14,7 @@ pub struct Settings { #[derive(Serialize, Deserialize, Clone, Debug)] pub struct ServerSettings { - pub address: String, + pub address: Option, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -31,9 +31,7 @@ impl Default for Settings { fn default() -> Self { Self { endpoints: HashMap::new(), - server: ServerSettings { - address: String::from("127.0.0.1:8080"), - }, + server: ServerSettings { address: None }, } } } @@ -52,11 +50,11 @@ fn load_settings() -> MultihookResult { .unwrap_or(PathBuf::from(".config")); if !Path::new(&config_dir).exists() { fs::create_dir(&config_dir)?; + write_toml_pretty( + &config_dir.clone().join("config.toml"), + &Settings::default(), + )?; } - write_toml_pretty( - &config_dir.clone().join("default-config.toml"), - &Settings::default(), - )?; let mut settings = config::Config::default(); settings