feat: with basic server
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
36
crates/hyperlog-server/src/lib.rs
Normal file
36
crates/hyperlog-server/src/lib.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
|
||||
use crate::state::{SharedState, State};
|
||||
|
||||
mod external_http;
|
||||
mod internal_http;
|
||||
mod state;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ServeOptions {
|
||||
pub external_http: SocketAddr,
|
||||
pub internal_http: SocketAddr,
|
||||
}
|
||||
|
||||
pub async fn serve(opts: ServeOptions) -> anyhow::Result<()> {
|
||||
let ctrl_c = async {
|
||||
tokio::signal::ctrl_c().await.unwrap();
|
||||
tracing::info!("kill signal received, shutting down");
|
||||
};
|
||||
tracing::debug!("setting up dependencies");
|
||||
let state = SharedState(Arc::new(State::new().await?));
|
||||
|
||||
tracing::debug!("serve starting");
|
||||
tokio::select!(
|
||||
res = external_http::serve(&state, &opts.external_http) => {
|
||||
res?
|
||||
},
|
||||
res = internal_http::serve(&state, &opts.internal_http) => {
|
||||
res?
|
||||
},
|
||||
() = ctrl_c => {}
|
||||
);
|
||||
tracing::debug!("serve finalized");
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user