blob: a17e2b27ae503133b17a1e9b490e3f834c917d2e (
plain) (
tree)
|
|
use crate::error::TwinHError;
use hyper::{
service::{make_service_fn, service_fn},
Server,
};
use log::LevelFilter;
#[macro_use]
extern crate lazy_static;
mod config;
mod error;
mod import;
mod models;
mod repo;
mod routes;
mod templates;
#[tokio::main]
async fn main() -> Result<(), TwinHError> {
// configure logger
let level = match config::INSTANCE.verbose {
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Warn,
};
env_logger::builder().filter_level(level).init();
// create HTTP listener
let make_svc =
make_service_fn(move |_conn| async { Ok::<_, TwinHError>(service_fn(routes::router)) });
// bind server with signal
let server = Server::bind(&config::INSTANCE.bind_addr.into()).serve(make_svc);
let graceful = server.with_graceful_shutdown(shutdown_signal());
// start and wait for shutdown
graceful.await?;
Ok(())
}
async fn shutdown_signal() {
// Wait for CTRL+C
tokio::signal::ctrl_c()
.await
.expect("failed to install CTRL+C signal handler");
}
|