2024-05-18 20:45:35 +02:00
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
use quote::quote;
|
|
|
|
|
use syn::{parse_macro_input, ItemFn};
|
|
|
|
|
|
|
|
|
|
pub fn handler_core(_args: TokenStream, item: TokenStream) -> TokenStream {
|
|
|
|
|
let item = parse_macro_input!(item as ItemFn);
|
|
|
|
|
|
|
|
|
|
let fn_name = item.clone().sig.ident;
|
|
|
|
|
|
|
|
|
|
quote! {
|
2024-07-02 21:59:30 +02:00
|
|
|
use tuono_lib::axum::response::IntoResponse;
|
2024-06-02 20:32:53 +02:00
|
|
|
use std::collections::HashMap;
|
2024-07-02 21:59:30 +02:00
|
|
|
use tuono_lib::axum::extract::{State, Path};
|
2024-05-30 21:03:25 +02:00
|
|
|
use reqwest::Client;
|
2024-05-18 20:45:35 +02:00
|
|
|
|
|
|
|
|
#item
|
|
|
|
|
|
2024-06-02 20:32:53 +02:00
|
|
|
pub async fn route(
|
2024-06-15 12:15:51 +02:00
|
|
|
Path(params): Path<HashMap<String, String>>,
|
|
|
|
|
State(client): State<Client>,
|
2024-07-02 21:59:30 +02:00
|
|
|
request: tuono_lib::axum::extract::Request
|
2024-06-15 12:15:51 +02:00
|
|
|
) -> impl IntoResponse {
|
2024-05-19 12:22:56 +02:00
|
|
|
let pathname = &request.uri();
|
|
|
|
|
let headers = &request.headers();
|
|
|
|
|
|
2024-06-02 20:32:53 +02:00
|
|
|
let req = tuono_lib::Request::new(pathname, headers, params);
|
2024-05-19 12:22:56 +02:00
|
|
|
|
2024-06-15 12:15:51 +02:00
|
|
|
#fn_name(req.clone(), client).await.render_to_string(req)
|
2024-05-20 21:07:37 +02:00
|
|
|
}
|
|
|
|
|
|
2024-06-02 20:32:53 +02:00
|
|
|
pub async fn api(
|
2024-06-15 12:15:51 +02:00
|
|
|
Path(params): Path<HashMap<String, String>>,
|
|
|
|
|
State(client): State<Client>,
|
2024-07-02 21:59:30 +02:00
|
|
|
request: tuono_lib::axum::extract::Request
|
2024-06-15 12:15:51 +02:00
|
|
|
) -> impl IntoResponse{
|
2024-06-15 12:31:39 +02:00
|
|
|
let pathname = &request.uri();
|
2024-05-20 21:07:37 +02:00
|
|
|
let headers = &request.headers();
|
|
|
|
|
|
2024-06-02 20:32:53 +02:00
|
|
|
let req = tuono_lib::Request::new(pathname, headers, params);
|
2024-05-20 21:07:37 +02:00
|
|
|
|
2024-06-15 12:15:51 +02:00
|
|
|
#fn_name(req.clone(), client).await.json()
|
2024-05-18 20:45:35 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.into()
|
|
|
|
|
}
|