use std::net::SocketAddr;
use async_trait::async_trait;
use axum::Router;
use crate::{adapter::Adapter, context::Context, errors::Error, signal::shutdown_signal, Result};
#[async_trait]
pub trait LifeCycle {
#[must_use]
fn version() -> String {
"dev".to_string()
}
fn app_name() -> &'static str;
async fn rest(ctx: &Context, app: Router) -> Result<()> {
let settings = ctx.configs.clone().expect("load configuration failed.");
let address = format!("{}:{}", settings.server.host, settings.server.port);
let listener = tokio::net::TcpListener::bind(&address).await?;
tracing::info!("Listening on {}", &address);
match axum::serve(
listener,
app.into_make_service_with_connect_info::<SocketAddr>(),
)
.with_graceful_shutdown(shutdown_signal())
.await
{
Ok(()) => Ok(()),
Err(e) => Err(Error::Message(format!("{}", e))),
}
}
async fn adapters() -> Result<Vec<Box<dyn Adapter>>> {
Ok(vec![])
}
fn routes(ctx: Context) -> Router;
}