44 lines
1.1 KiB
Rust
44 lines
1.1 KiB
Rust
mod cmd;
|
|
mod ctrl;
|
|
mod ctx;
|
|
mod event;
|
|
mod model;
|
|
mod rpc;
|
|
|
|
use std::str::FromStr;
|
|
|
|
use nzr_api::config;
|
|
|
|
#[tokio::main(flavor = "multi_thread")]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let cfg: config::Config = config::Config::figment().extract()?;
|
|
let ctx = ctx::Context::new(cfg).await?;
|
|
|
|
let mut bad_loglevel = false;
|
|
let log_level = tracing::Level::from_str(&ctx.config.log_level).unwrap_or_else(|_| {
|
|
bad_loglevel = true;
|
|
tracing::Level::WARN
|
|
});
|
|
|
|
tracing_subscriber::fmt().with_max_level(log_level).init();
|
|
|
|
if bad_loglevel {
|
|
tracing::warn!("Couldn't parse log level from config, defaulting to {log_level}");
|
|
}
|
|
|
|
// Run both the RPC and events servers
|
|
tokio::select! {
|
|
res = rpc::serve(ctx.clone()) => {
|
|
if let Err(err) = res {
|
|
tracing::error!("RPC server error: {err}");
|
|
}
|
|
},
|
|
res = event::event_server(ctx.clone()) => {
|
|
if let Err(err) = res {
|
|
tracing::error!("Event server error: {err}");
|
|
}
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|