This repository has been archived on 2025-04-14. You can view files and clone it, but cannot push or open issues or pull requests.
axum-controller/axum-controller/examples/controller.rs
2025-03-04 14:26:04 +01:00

43 lines
1,008 B
Rust

use axum::extract::State;
use axum_controller::*;
struct ExampleController;
async fn my_middleware(
request: axum::extract::Request,
next: axum::middleware::Next,
) -> axum::response::Response {
next.run(request).await
}
async fn my_other_middleware(
request: axum::extract::Request,
next: axum::middleware::Next,
) -> axum::response::Response {
next.run(request).await
}
#[derive(Clone, Debug)]
struct AppState();
#[controller(
path = "/asd",
state = AppState,
middleware=axum::middleware::from_fn(my_middleware),
middleware=axum::middleware::from_fn(my_other_middleware),
)]
impl ExampleController {
#[route(GET "/test")]
async fn test_handler_fn(_: State<AppState>) -> String {
todo!("handle request")
}
#[route(GET "/test2")]
async fn test_handler_fn2(State(_): State<AppState>) -> String {
todo!("handle request")
}
}
fn main() {
let _router: axum::Router<AppState>= ExampleController.into_router(AppState());
}