loadstar/src/router.rs

27 lines
552 B
Rust
Raw Normal View History

2024-08-20 06:05:01 +00:00
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),
}
}
}