/* * tmtd - Suckless To Do list * Copyright (C) 2022 C4TG1RL5 * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ use crate::{config::Config, database::Database}; use std::str::FromStr; use std::{env, sync::Arc}; use tracing::{info, Level}; mod config; mod database; mod task; mod templates; mod web; #[tokio::main(flavor = "current_thread")] async fn main() -> anyhow::Result<()> { let cfg = Config::load()?; tracing_subscriber::fmt::fmt() .with_max_level({ if let Some(o) = cfg.log_level.as_deref() { Level::from_str(o)? } else { Level::INFO } }) .init(); info!(concat!("Initializing - tmtd ", env!("CARGO_PKG_VERSION"))); let database = Arc::new(Database::connect(&cfg.connection_string).await?); let web = web::App::new(cfg.listen_addr, database.clone()).await?; info!("Started the web app at http://{}", cfg.listen_addr); web.server.await?; database.close().await; Ok(()) }