aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-08-27 15:26:19 +0200
committerAlex Auvolat <alex@adnab.me>2023-08-27 15:26:19 +0200
commitb5e8d1fcd800330edfc4e8deed5229d172ec1248 (patch)
treee1377e66ac3f16cd6c5136aa0933da9433b3e48e /src/main.rs
parent48a421a3b6c07705b67276853643ed5601a30154 (diff)
downloadtricot-b5e8d1fcd800330edfc4e8deed5229d172ec1248.tar.gz
tricot-b5e8d1fcd800330edfc4e8deed5229d172ec1248.zip
stdout: prettier formatting of proxy config
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 43f3447..f84d973 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@
extern crate anyhow;
use log::*;
+use std::collections::BTreeMap;
use std::sync::Arc;
use std::time::Instant;
@@ -218,6 +219,8 @@ async fn dump_config_on_change(
mut rx_proxy_config: watch::Receiver<Arc<ProxyConfig>>,
mut must_exit: watch::Receiver<bool>,
) {
+ let mut old_cfg: Arc<ProxyConfig> = rx_proxy_config.borrow().clone();
+
while !*must_exit.borrow() {
select!(
c = rx_proxy_config.changed() => {
@@ -227,11 +230,28 @@ async fn dump_config_on_change(
}
_ = must_exit.changed() => continue,
);
- println!("---- PROXY CONFIGURATION ----");
- for ent in rx_proxy_config.borrow().entries.iter() {
- println!(" {}", ent);
+
+ let cfg: Arc<ProxyConfig> = rx_proxy_config.borrow().clone();
+ if cfg != old_cfg {
+ let mut cfg_map = BTreeMap::<_, Vec<_>>::new();
+ for ent in cfg.entries.iter() {
+ cfg_map
+ .entry((&ent.host, &ent.path_prefix))
+ .or_default()
+ .push(ent);
+ }
+
+ println!("---- PROXY CONFIGURATION ----");
+ for ((host, prefix), ents) in cfg_map.iter_mut() {
+ println!("{}{}:", host, prefix.as_deref().unwrap_or_default());
+ for ent in ents.iter() {
+ println!(" {}", ent);
+ }
+ }
+ println!();
+
+ old_cfg = cfg;
}
- println!();
}
}