loadstar/src/router.rs
2024-08-20 08:05:01 +02:00

27 lines
552 B
Rust

use std::collections::HashMap;
use tiny_http::Request;
use crate::{entities::request::Url, utilities::responses::respond_not_found};
pub struct Router {
routes: HashMap<String, fn(Request)>,
}
impl Router {
pub fn new() -> Self {
let routes = HashMap::new();
Router { routes }
}
pub async fn route(&self, request: Request) {
match self.routes.get(&request.get_url_without_parameters()) {
Some(handler) => handler(request),
None => respond_not_found(request),
}
}
}