1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{HTTPResponse, ResponseBuilder, Verb};

use super::ParamsHandler;

#[derive(PartialEq, Eq,Debug)]
pub struct Route{
    pub verb  : Verb,
    pub route:  String,
    pub method : fn(ParamsHandler) -> HTTPResponse,
    pub need_security: bool
}

impl Clone for Route {
    fn clone(&self) -> Self {
        Route { route: self.route.clone(), ..*self }
    }
}

impl Default for Route {
    fn default() -> Self {
        Self { verb: Verb::GET, route: "/".to_string(), method: default_method, need_security: false }
    }
}

fn default_method(_: ParamsHandler) -> HTTPResponse {
    ResponseBuilder::new(200, Some("default".to_string())).build()
}

pub type Routes = Vec<Route>;