rename MethodInfo to Router
This commit is contained in:
parent
10be1d290a
commit
e63e99d646
|
@ -24,9 +24,9 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error
|
||||||
Ok(json!(null))
|
Ok(json!(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn router() -> MethodInfo {
|
pub fn router() -> Router {
|
||||||
|
|
||||||
let route = MethodInfo::new()
|
let route = Router::new()
|
||||||
.get(ApiMethod {
|
.get(ApiMethod {
|
||||||
handler: test_sync_api_handler,
|
handler: test_sync_api_handler,
|
||||||
description: "This is a simple test.",
|
description: "This is a simple test.",
|
||||||
|
|
|
@ -8,13 +8,13 @@ use hyper::Method;
|
||||||
|
|
||||||
pub struct ApiConfig {
|
pub struct ApiConfig {
|
||||||
basedir: PathBuf,
|
basedir: PathBuf,
|
||||||
router: &'static MethodInfo,
|
router: &'static Router,
|
||||||
aliases: HashMap<String, PathBuf>,
|
aliases: HashMap<String, PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApiConfig {
|
impl ApiConfig {
|
||||||
|
|
||||||
pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static MethodInfo) -> Self {
|
pub fn new<B: Into<PathBuf>>(basedir: B, router: &'static Router) -> Self {
|
||||||
Self {
|
Self {
|
||||||
basedir: basedir.into(),
|
basedir: basedir.into(),
|
||||||
router: router,
|
router: router,
|
||||||
|
|
|
@ -11,15 +11,15 @@ pub struct ApiMethod {
|
||||||
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
|
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MethodInfo {
|
pub struct Router {
|
||||||
pub get: Option<ApiMethod>,
|
pub get: Option<ApiMethod>,
|
||||||
pub put: Option<ApiMethod>,
|
pub put: Option<ApiMethod>,
|
||||||
pub post: Option<ApiMethod>,
|
pub post: Option<ApiMethod>,
|
||||||
pub delete: Option<ApiMethod>,
|
pub delete: Option<ApiMethod>,
|
||||||
pub subdirs: Option<HashMap<String, MethodInfo>>,
|
pub subdirs: Option<HashMap<String, Router>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MethodInfo {
|
impl Router {
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -36,7 +36,7 @@ impl MethodInfo {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_route(&self, components: &[&str]) -> Option<&MethodInfo> {
|
pub fn find_route(&self, components: &[&str]) -> Option<&Router> {
|
||||||
|
|
||||||
if components.len() == 0 { return Some(self); };
|
if components.len() == 0 { return Some(self); };
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ impl MethodInfo {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! methodinfo {
|
macro_rules! methodinfo {
|
||||||
($($option:ident => $e:expr),*) => {{
|
($($option:ident => $e:expr),*) => {{
|
||||||
let info = MethodInfo::new();
|
let info = Router::new();
|
||||||
|
|
||||||
$(
|
$(
|
||||||
info.$option = Some($e);
|
info.$option = Some($e);
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
||||||
let addr = ([127, 0, 0, 1], 8007).into();
|
let addr = ([127, 0, 0, 1], 8007).into();
|
||||||
|
|
||||||
lazy_static!{
|
lazy_static!{
|
||||||
static ref ROUTER: MethodInfo = apitest::api3::router();
|
static ref ROUTER: Router = apitest::api3::router();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = ApiConfig::new("/var/www", &ROUTER);
|
let mut config = ApiConfig::new("/var/www", &ROUTER);
|
||||||
|
|
Loading…
Reference in New Issue