Page abstraction
This commit is contained in:
@@ -13,3 +13,4 @@ tracing = { workspace = true }
|
||||
tower-http = { workspace = true }
|
||||
utoipa = { workspace = true }
|
||||
utoipa-swagger-ui = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user