move find_method to Router class

This commit is contained in:
Dietmar Maurer 2019-05-07 11:08:30 +02:00
parent 3578d99f3e
commit 01bf3b7b5f
2 changed files with 21 additions and 11 deletions

View File

@ -25,16 +25,7 @@ impl ApiConfig {
pub fn find_method(&self, components: &[&str], method: Method, uri_param: &mut HashMap<String, String>) -> &'static MethodDefinition {
if let Some(info) = self.router.find_route(components, uri_param) {
return match method {
Method::GET => &info.get,
Method::PUT => &info.put,
Method::POST => &info.post,
Method::DELETE => &info.delete,
_ => &MethodDefinition::None,
};
}
&MethodDefinition::None
self.router.find_method(components, method, uri_param)
}
pub fn find_alias(&self, components: &[&str]) -> PathBuf {

View File

@ -6,7 +6,7 @@ use std::collections::HashMap;
use std::sync::Arc;
use std::fmt;
use hyper::{Body, Response, StatusCode};
use hyper::{Body, Method, Response, StatusCode};
use hyper::rt::Future;
use hyper::http::request::Parts;
@ -305,4 +305,23 @@ impl Router {
None
}
pub fn find_method(
&self,
components: &[&str],
method: Method,
uri_param: &mut HashMap<String, String>
) -> &MethodDefinition {
if let Some(info) = self.find_route(components, uri_param) {
return match method {
Method::GET => &info.get,
Method::PUT => &info.put,
Method::POST => &info.post,
Method::DELETE => &info.delete,
_ => &MethodDefinition::None,
};
}
&MethodDefinition::None
}
}