pub const MIDDLEWARE_STUB: &str = r#"//! {%namespace%}::{%className%} 中间件
//!
//! 由 `sz-rust make:middleware` 生成。
//! 在中间件链配置中通过 `MiddlewareChain::add(MiddlewareKind::{%className%})` 注册。
use sz_rust_core::middleware::SzMiddleware;
use axum::{body::Body, http::Request, response::Response};
/// {%className%} 中间件
pub struct {%className%};
#[sz_rust_core::middleware]
impl SzMiddleware for {%className%} {
async fn handle(
&self,
req: Request<Body>,
next: impl FnOnce(Request<Body>) -> std::pin::Pin<Box<dyn std::future::Future<Output = Response> + Send>>
) -> Response {
// 前置处理
// tracing::info!("请求进入 {%className%}: {}", req.uri().path());
let response = next(req).await;
// 后置处理
// tracing::info!("响应离开 {%className%}: {}", response.status());
response
}
}
"#;Expand description
中间件模板(对齐 PHP make:middleware)
生成基于 SzMiddleware trait 的中间件骨架。