split router::serve units.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-05-30 22:38:39 +00:00 committed by June 🍓🦴
parent 0baa57f5d9
commit 2e45cb281a
7 changed files with 245 additions and 218 deletions

26
src/router/serve/mod.rs Normal file
View file

@ -0,0 +1,26 @@
mod plain;
mod tls;
mod unix;
use std::sync::Arc;
use axum::{routing::IntoMakeService, Router};
use axum_server::Handle as ServerHandle;
use conduit::{Error, Result, Server};
use tokio::sync::broadcast;
/// Serve clients
pub(super) async fn serve(
server: &Arc<Server>, app: IntoMakeService<Router>, handle: ServerHandle, shutdown: broadcast::Receiver<()>,
) -> Result<(), Error> {
let config = &server.config;
let addrs = config.get_bind_addrs();
if cfg!(unix) && config.unix_socket_path.is_some() {
unix::serve(server, app, shutdown).await
} else if config.tls.is_some() {
tls::serve(server, app, handle, addrs).await
} else {
plain::serve(server, app, handle, addrs).await
}
}