move main.rs functionality to lib.rs
This commit is contained in:
parent
7527459446
commit
8b76a51434
53
src/lib.rs
Normal file
53
src/lib.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
use crate::cli::{Listen, ListenFdSocket, ListenFdSockets};
|
||||
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
|
||||
use actix_web::{cookie::Key, web, App, HttpServer};
|
||||
use clap::Parser;
|
||||
use listenfd::ListenFd;
|
||||
|
||||
mod app;
|
||||
mod cli;
|
||||
mod client;
|
||||
mod config;
|
||||
|
||||
pub async fn main() -> eyre::Result<()> {
|
||||
env_logger::init();
|
||||
let mut listenfd = ListenFd::from_env();
|
||||
color_eyre::install()?;
|
||||
let mut args = cli::CLI::parse();
|
||||
args.resolve(&mut listenfd).await?;
|
||||
log::info!("retrieved config from auth servers");
|
||||
let config = web::Data::new(args.config);
|
||||
let cookie_session_key = Key::generate();
|
||||
let mut server = HttpServer::new(move || {
|
||||
let cookie_session =
|
||||
SessionMiddleware::builder(CookieSessionStore::default(), cookie_session_key.clone())
|
||||
.cookie_name("session".into())
|
||||
.build();
|
||||
App::new()
|
||||
.wrap(cookie_session)
|
||||
.app_data(config.clone())
|
||||
.configure(app::all_services)
|
||||
});
|
||||
let Listen {
|
||||
listen_tcp,
|
||||
listen_unix,
|
||||
listen_fd,
|
||||
} = &mut args.listen;
|
||||
for sock in listen_tcp.iter() {
|
||||
server = server.bind_auto_h2c(sock)?;
|
||||
}
|
||||
for sock in listen_unix.iter() {
|
||||
server = server.bind_uds(sock)?;
|
||||
}
|
||||
if let Some(ListenFdSockets(sockets)) = listen_fd {
|
||||
for sock in sockets.drain(..) {
|
||||
server = match sock {
|
||||
ListenFdSocket::Tcp(sock) => server.listen_auto_h2c(sock)?,
|
||||
ListenFdSocket::Unix(sock) => server.listen_uds(sock)?,
|
||||
};
|
||||
}
|
||||
}
|
||||
log::info!("started server");
|
||||
server.run().await?;
|
||||
Ok(())
|
||||
}
|
52
src/main.rs
52
src/main.rs
|
@ -1,54 +1,4 @@
|
|||
use crate::cli::{Listen, ListenFdSocket, ListenFdSockets};
|
||||
use actix_session::{storage::CookieSessionStore, SessionMiddleware};
|
||||
use actix_web::{cookie::Key, web, App, HttpServer};
|
||||
use clap::Parser;
|
||||
use listenfd::ListenFd;
|
||||
|
||||
mod app;
|
||||
mod cli;
|
||||
mod client;
|
||||
mod config;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
env_logger::init();
|
||||
let mut listenfd = ListenFd::from_env();
|
||||
color_eyre::install()?;
|
||||
let mut args = cli::CLI::parse();
|
||||
args.resolve(&mut listenfd).await?;
|
||||
log::info!("retrieved config from auth servers");
|
||||
let config = web::Data::new(args.config);
|
||||
let cookie_session_key = Key::generate();
|
||||
let mut server = HttpServer::new(move || {
|
||||
let cookie_session =
|
||||
SessionMiddleware::builder(CookieSessionStore::default(), cookie_session_key.clone())
|
||||
.cookie_name("session".into())
|
||||
.build();
|
||||
App::new()
|
||||
.wrap(cookie_session)
|
||||
.app_data(config.clone())
|
||||
.configure(app::all_services)
|
||||
});
|
||||
let Listen {
|
||||
listen_tcp,
|
||||
listen_unix,
|
||||
listen_fd,
|
||||
} = &mut args.listen;
|
||||
for sock in listen_tcp.iter() {
|
||||
server = server.bind_auto_h2c(sock)?;
|
||||
}
|
||||
for sock in listen_unix.iter() {
|
||||
server = server.bind_uds(sock)?;
|
||||
}
|
||||
if let Some(ListenFdSockets(sockets)) = listen_fd {
|
||||
for sock in sockets.drain(..) {
|
||||
server = match sock {
|
||||
ListenFdSocket::Tcp(sock) => server.listen_auto_h2c(sock)?,
|
||||
ListenFdSocket::Unix(sock) => server.listen_uds(sock)?,
|
||||
};
|
||||
}
|
||||
}
|
||||
log::info!("started server");
|
||||
server.run().await?;
|
||||
Ok(())
|
||||
subscribe_list::main().await
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue