1 use crate::api
::router
::*;
3 use std
::collections
::HashMap
;
4 use std
::path
::{PathBuf}
;
10 router
: &'
static Router
,
11 aliases
: HashMap
<String
, PathBuf
>,
12 env_type
: RpcEnvironmentType
,
17 pub fn new
<B
: Into
<PathBuf
>>(basedir
: B
, router
: &'
static Router
, env_type
: RpcEnvironmentType
) -> Self {
19 basedir
: basedir
.into(),
21 aliases
: HashMap
::new(),
26 pub fn find_method(&self, components
: &[&str], method
: Method
, uri_param
: &mut HashMap
<String
, String
>) -> &'
static MethodDefinition
{
28 if let Some(info
) = self.router
.find_route(components
, uri_param
) {
30 Method
::GET
=> &info
.get
,
31 Method
::PUT
=> &info
.put
,
32 Method
::POST
=> &info
.post
,
33 Method
::DELETE
=> &info
.delete
,
34 _
=> &MethodDefinition
::None
,
37 &MethodDefinition
::None
40 pub fn find_alias(&self, components
: &[&str]) -> PathBuf
{
42 let mut prefix
= String
::new();
43 let mut filename
= self.basedir
.clone();
44 let comp_len
= components
.len();
46 prefix
.push_str(components
[0]);
47 if let Some(subdir
) = self.aliases
.get(&prefix
) {
48 filename
.push(subdir
);
49 for i
in 1..comp_len { filename.push(components[i]) }
51 for i
in 0..comp_len { filename.push(components[i]) }
57 pub fn add_alias
<S
, P
>(&mut self, alias
: S
, path
: P
)
58 where S
: Into
<String
>,
61 self.aliases
.insert(alias
.into(), path
.into());
64 pub fn env_type(&self) -> RpcEnvironmentType
{