No need to pass tracing guard

This commit is contained in:
Mo 2022-12-03 17:15:49 +01:00
parent be7b29d631
commit 1f61efb1b6

View file

@ -16,9 +16,8 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::process; use std::process;
use std::sync::Arc; use std::sync::Arc;
use tracing::info; use tracing::info;
use tracing_appender::non_blocking::WorkerGuard;
async fn init() -> Result<WorkerGuard> { async fn init() -> Result<()> {
let mut config = config::Config::new()?; let mut config = config::Config::new()?;
let path_prefix = config.path_prefix.clone(); let path_prefix = config.path_prefix.clone();
let mailer = Arc::new(mailer::Mailer::new(&mut config)?); let mailer = Arc::new(mailer::Mailer::new(&mut config)?);
@ -31,7 +30,7 @@ async fn init() -> Result<WorkerGuard> {
config.socket_address.port, config.socket_address.port,
); );
let tracing_worker_gurad = logging::init_logger(&config.logging); let _tracing_gurad = logging::init_logger(&config.logging);
let config = Arc::new(config); let config = Arc::new(config);
let captcha_solutions = Arc::new(captcha_solutions::SharedCaptchaSolutions::default()); let captcha_solutions = Arc::new(captcha_solutions::SharedCaptchaSolutions::default());
@ -42,14 +41,14 @@ async fn init() -> Result<WorkerGuard> {
captcha_solutions, captcha_solutions,
}; };
let spa = SpaRouter::new(&format!("{}/static", &path_prefix), "static");
let routes = Router::new() let routes = Router::new()
.route("/", get(routes::index)) .route("/", get(routes::index))
.route("/", post(routes::submit)) .route("/", post(routes::submit))
.route("/success", get(routes::success)) .route("/success", get(routes::success))
.with_state(app_state); .with_state(app_state);
let spa = SpaRouter::new(&format!("{}/static", &path_prefix), "static");
let app = Router::new().nest(&path_prefix, routes).merge(spa); let app = Router::new().nest(&path_prefix, routes).merge(spa);
info!("Starting server"); info!("Starting server");
@ -58,12 +57,12 @@ async fn init() -> Result<WorkerGuard> {
.await .await
.unwrap(); .unwrap();
Ok(tracing_worker_gurad) Ok(())
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let _tracing_worker_gurad = init().await.unwrap_or_else(|e| { init().await.unwrap_or_else(|e| {
eprintln!("{e:?}"); eprintln!("{e:?}");
process::exit(1); process::exit(1);
}); });