diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 28 |
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!(); } } |