From: Ian Jackson Date: Sun, 8 Aug 2021 00:21:07 +0000 (+0100) Subject: config: Provide a startup hook X-Git-Tag: hippotat/1.0.0~240 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7260a1a5c8a2f821020fa6782fe61a3a706f660b;p=hippotat.git config: Provide a startup hook Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index 646006c..491fec3 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -302,8 +302,8 @@ async fn run_client( #[tokio::main] async fn main() { let opts = Opts::from_args(); - let (ics,) = config::startup("hippotat", LinkEnd::Client, - &opts.config, &opts.log); + let (ics,()) = config::startup("hippotat", LinkEnd::Client, + &opts.config, &opts.log, |_|Ok(())); let https = HttpsConnector::new(); let hclient = hyper::Client::builder().build::<_, hyper::Body>(https); diff --git a/src/bin/server.rs b/src/bin/server.rs index 6bc1df7..4869ce8 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -16,10 +16,12 @@ pub struct Opts { #[tokio::main] async fn main() { let opts = Opts::from_args(); - let (ics,) = config::startup("hippotatd", LinkEnd::Server, - &opts.config, &opts.log); - - let global = config::InstanceConfigGlobal::from(&ics); + let (ics,global) = config::startup("hippotatd", LinkEnd::Server, + &opts.config, &opts.log, |ics| + { + let global = config::InstanceConfigGlobal::from(&ics); + Ok(global) + }); dbg!(ics, global); } diff --git a/src/config.rs b/src/config.rs index 048a91c..3a45eb8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -887,9 +887,11 @@ pub fn read(opts: &Opts, end: LinkEnd) -> Vec { ics } -pub fn startup(progname: &str, end: LinkEnd, - opts: &Opts, logopts: &LogOpts) - -> (Vec,) +pub fn startup(progname: &str, end: LinkEnd, + opts: &Opts, logopts: &LogOpts, + f: F) + -> (Vec,T) + where F: FnOnce(&[InstanceConfig]) -> Result { (||{ dedup_eyre_setup()?; @@ -897,8 +899,9 @@ pub fn startup(progname: &str, end: LinkEnd, if ics.is_empty() { throw!(anyhow!("no associations, quitting")); } logopts.log_init()?; + let t = f(&ics)?; - Ok::<_,AE>((ics,)) + Ok::<_,AE>((ics,t)) })().unwrap_or_else(|e| { eprintln!("{}: startup error: {}", progname, &e); process::exit(8);