Page abstraction
All checks were successful
CI / Check typos (push) Successful in 10s
CI / Check links (push) Successful in 34s
CI / Clippy (push) Successful in 41s
CI / Build and test (push) Successful in 2m4s
CI / Build container (push) Successful in 3m15s

This commit is contained in:
2025-11-04 08:55:14 -08:00
parent acc057e4cb
commit 4504a88f4b
20 changed files with 522 additions and 233 deletions

View File

@@ -13,3 +13,4 @@ tracing = { workspace = true }
tower-http = { workspace = true }
utoipa = { workspace = true }
utoipa-swagger-ui = { workspace = true }
tokio = { workspace = true }

View File

@@ -1,5 +1,4 @@
//! Abstractions for modular http API routes
use axum::{
Json, Router,
extract::{Request, State},
@@ -7,7 +6,10 @@ use axum::{
middleware::Next,
response::{IntoResponse, Response},
};
use axum::{extract::connect_info::Connected, serve::IncomingStream};
use std::ops::Deref;
use std::{net::SocketAddr, sync::Arc};
use tokio::net::TcpListener;
use tower_http::trace::TraceLayer;
use tracing::info;
use utoipa::openapi::{
@@ -16,6 +18,22 @@ use utoipa::openapi::{
};
use utoipa_swagger_ui::SwaggerUi;
/// For use with `into_make_service_with_connect_info`
#[derive(Clone, Debug)]
pub struct ServiceConnectInfo {
pub addr: Arc<SocketAddr>,
}
impl Connected<IncomingStream<'_, TcpListener>> for ServiceConnectInfo {
fn connect_info(target: IncomingStream<'_, TcpListener>) -> Self {
let addr = target.remote_addr();
Self {
addr: Arc::new(*addr),
}
}
}
/// A `Service` provides a set of api endpoints and docs.
/// This has no relation to [tower::Service].
pub trait ToService
@@ -26,7 +44,9 @@ where
fn make_router(&self) -> Option<Router<()>>;
/// Create an openapi spec for this service
fn make_openapi(&self) -> OpenApi;
fn make_openapi(&self) -> OpenApi {
OpenApi::default()
}
/// Get the service name for grouping endpoints
fn service_name(&self) -> Option<String> {