cleanup module names
This commit is contained in:
parent
c0262d7480
commit
f17db0abfd
|
@ -1,5 +1,4 @@
|
|||
use crate::api_info::*;
|
||||
//use crate::json_schema::*;
|
||||
use crate::api::router::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::path::{PathBuf};
|
|
@ -1,6 +1,6 @@
|
|||
use crate::json_schema::*;
|
||||
use crate::api_info::*;
|
||||
use crate::api_config::*;
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use crate::api::config::*;
|
||||
|
||||
use std::fmt;
|
||||
use std::path::{PathBuf};
|
|
@ -2,8 +2,8 @@ use failure::*;
|
|||
use std::collections::HashMap;
|
||||
|
||||
|
||||
use crate::json_schema::*;
|
||||
use crate::api_info::*;
|
||||
use crate::api::schema::*;
|
||||
use crate::api::router::*;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
use failure::*;
|
||||
|
||||
use crate::json_schema::*;
|
||||
use serde_json::{Value};
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct ApiMethod {
|
||||
pub description: &'static str,
|
||||
pub parameters: Schema,
|
||||
pub returns: Schema,
|
||||
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
|
||||
}
|
||||
|
||||
pub enum SubRoute {
|
||||
None,
|
||||
Hash(HashMap<String, Router>),
|
||||
MatchAll { router: Box<Router>, param_name: String },
|
||||
}
|
||||
|
||||
pub struct Router {
|
||||
pub get: Option<ApiMethod>,
|
||||
pub put: Option<ApiMethod>,
|
||||
pub post: Option<ApiMethod>,
|
||||
pub delete: Option<ApiMethod>,
|
||||
pub subroute: SubRoute,
|
||||
}
|
||||
|
||||
impl Router {
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
get: None,
|
||||
put: None,
|
||||
post: None,
|
||||
delete: None,
|
||||
subroute: SubRoute::None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subdirs(mut self, map: HashMap<String, Router>) -> Self {
|
||||
self.subroute = SubRoute::Hash(map);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn match_all(mut self, router: Router) -> Self {
|
||||
self.subroute = SubRoute::MatchAll { router: Box::new(router), param_name: "test".into() };
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get(mut self, m: ApiMethod) -> Self {
|
||||
self.get = Some(m);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn find_route(&self, components: &[&str]) -> Option<&Router> {
|
||||
|
||||
if components.len() == 0 { return Some(self); };
|
||||
|
||||
let (dir, rest) = (components[0], &components[1..]);
|
||||
|
||||
match self.subroute {
|
||||
SubRoute::None => {},
|
||||
SubRoute::Hash(ref dirmap) => {
|
||||
if let Some(ref router) = dirmap.get(dir) {
|
||||
println!("FOUND SUBDIR {}", dir);
|
||||
return router.find_route(rest);
|
||||
}
|
||||
}
|
||||
SubRoute::MatchAll { ref router, ref param_name } => {
|
||||
println!("URI PARAM {} = {}", param_name, dir); // fixme: store somewhere
|
||||
return router.find_route(rest);
|
||||
},
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
// fixme: remove - not required?
|
||||
#[macro_export]
|
||||
macro_rules! methodinfo {
|
||||
($($option:ident => $e:expr),*) => {{
|
||||
let info = Router::new();
|
||||
|
||||
$(
|
||||
info.$option = Some($e);
|
||||
)*
|
||||
|
||||
info
|
||||
}}
|
||||
}
|
13
src/lib.rs
13
src/lib.rs
|
@ -1,14 +1,17 @@
|
|||
pub mod static_map;
|
||||
|
||||
#[macro_use]
|
||||
pub mod json_schema;
|
||||
pub mod api {
|
||||
|
||||
#[macro_use]
|
||||
pub mod api_info;
|
||||
#[macro_use]
|
||||
pub mod schema;
|
||||
#[macro_use]
|
||||
pub mod router;
|
||||
pub mod config;
|
||||
pub mod server;
|
||||
|
||||
pub mod api_config;
|
||||
}
|
||||
|
||||
pub mod api_server;
|
||||
|
||||
pub mod api3;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//use apitest::json_schema::*;
|
||||
use apitest::api_info::*;
|
||||
use apitest::api_config::*;
|
||||
use apitest::api_server::*;
|
||||
use apitest::api::router::*;
|
||||
use apitest::api::config::*;
|
||||
use apitest::api::server::*;
|
||||
|
||||
//use failure::*;
|
||||
use lazy_static::lazy_static;
|
||||
|
|
Loading…
Reference in New Issue