tmtd/src/main.rs

53 lines
1.6 KiB
Rust
Raw Permalink Normal View History

2022-04-03 10:08:20 -05:00
/*
* tmtd - Suckless To Do list
2022-04-09 10:31:10 -05:00
* Copyright (C) 2022 C4TG1RL5
2022-04-03 10:08:20 -05:00
*
* 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 <http://www.gnu.org/licenses/>.
*/
use crate::{config::Config, database::Database};
2022-04-05 09:48:29 -05:00
use std::str::FromStr;
2022-04-09 10:30:20 -05:00
use std::{env, sync::Arc};
2022-05-30 13:10:06 -05:00
use tracing::{info, Level};
2022-04-03 10:08:20 -05:00
mod config;
mod database;
2022-04-10 06:03:52 -05:00
mod task;
2022-05-10 09:34:13 -05:00
mod templates;
2022-04-05 09:48:29 -05:00
mod web;
2022-04-03 10:08:20 -05:00
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
2022-05-30 13:10:06 -05:00
let cfg = Config::load()?;
2022-04-05 09:48:29 -05:00
tracing_subscriber::fmt::fmt()
.with_max_level({
if let Some(o) = cfg.log_level.as_deref() {
Level::from_str(o)?
} else {
Level::INFO
}
})
.init();
2022-04-03 10:08:20 -05:00
info!(concat!("Initializing - tmtd ", env!("CARGO_PKG_VERSION")));
2022-05-13 17:07:11 -05:00
let database = Arc::new(Database::connect(&cfg.connection_string).await?);
2022-04-05 09:48:29 -05:00
2022-05-10 09:34:13 -05:00
let web = web::App::new(cfg.listen_addr, database.clone()).await?;
info!("Started the web app at http://{}", cfg.listen_addr);
web.server.await?;
2022-04-05 09:48:29 -05:00
database.close().await;
2022-04-03 10:08:20 -05:00
Ok(())
2022-04-02 18:08:48 -05:00
}