use genco::prelude::*;
fn main() -> genco::fmt::Result {
let health_route = rust! {
let health_route = warp::path!("health")
.and_then(handlers::health_handler);
};
let post_route = rust! {
let post_route = warp::path!("p")
.and(warp::body::json())
.and(warp::addr::remote())
.and_then(handlers::post_handler);
};
let get_route = rust! {
let get_route = warp::path!("g")
.and(warp::get())
.and(warp::query::<IncomingMessage>())
.and(warp::addr::remote())
.and_then(get_handler);
};
let user_selected_routes = vec!["health", "post"];
let mut selected_route_tokens = vec![];
for route in user_selected_routes {
match route {
"health" => selected_route_tokens.push(health_route.clone()),
"post" => selected_route_tokens.push(post_route.clone()),
"get" => selected_route_tokens.push(get_route.clone()),
_ => {}
}
}
let tokens: rust::Tokens = rust! {
use std::fs;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::{mpsc, RwLock};
pub mod handlers;
pub mod socket;
mod routes;
pub static CLIENTS: InitCell<Clients> = InitCell::new();
pub async fn start_server() {
let cors = cors();
#(for route in &selected_route_tokens {
#route
})*
let routes = health_route
.or(post_route)
.or(get_route)
.with(cors);
}
};
println!("{}", tokens.to_file_string()?);
Ok(())
}