rename MethodInfo to Router

This commit is contained in:
Dietmar Maurer 2018-11-15 11:46:13 +01:00
parent 10be1d290a
commit e63e99d646
4 changed files with 10 additions and 10 deletions

View File

@ -24,9 +24,9 @@ fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error
Ok(json!(null))
}
pub fn router() -> MethodInfo {
pub fn router() -> Router {
let route = MethodInfo::new()
let route = Router::new()
.get(ApiMethod {
handler: test_sync_api_handler,
description: "This is a simple test.",

View File

@ -8,13 +8,13 @@ use hyper::Method;
pub struct ApiConfig {
basedir: PathBuf,
router: &'static MethodInfo,
router: &'static Router,
aliases: HashMap<String, PathBuf>,
}
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 {
basedir: basedir.into(),
router: router,

View File

@ -11,15 +11,15 @@ pub struct ApiMethod {
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
}
pub struct MethodInfo {
pub struct Router {
pub get: Option<ApiMethod>,
pub put: Option<ApiMethod>,
pub post: 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 {
Self {
@ -36,7 +36,7 @@ impl MethodInfo {
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); };
@ -56,7 +56,7 @@ impl MethodInfo {
#[macro_export]
macro_rules! methodinfo {
($($option:ident => $e:expr),*) => {{
let info = MethodInfo::new();
let info = Router::new();
$(
info.$option = Some($e);

View File

@ -17,7 +17,7 @@ fn main() {
let addr = ([127, 0, 0, 1], 8007).into();
lazy_static!{
static ref ROUTER: MethodInfo = apitest::api3::router();
static ref ROUTER: Router = apitest::api3::router();
}
let mut config = ApiConfig::new("/var/www", &ROUTER);