]>
Commit | Line | Data |
---|---|---|
504b3597 | 1 | use failure::*; |
6ce50400 | 2 | //use std::collections::HashMap; |
504b3597 DM |
3 | |
4 | ||
f17db0ab DM |
5 | use crate::api::schema::*; |
6 | use crate::api::router::*; | |
504b3597 DM |
7 | use serde_json::{json, Value}; |
8 | ||
ea0b8b6e | 9 | pub mod config; |
6ce50400 DM |
10 | mod version; |
11 | ||
08bd8d47 | 12 | fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> { |
504b3597 DM |
13 | println!("This is a test {}", param); |
14 | ||
15 | // let force: Option<bool> = Some(false); | |
16 | ||
17 | //if let Some(force) = param.force { | |
18 | //} | |
19 | ||
20 | let _force = param["force"].as_bool() | |
21 | .ok_or_else(|| format_err!("missing parameter 'force'"))?; | |
22 | ||
23 | if let Some(_force) = param["force"].as_bool() { | |
24 | } | |
25 | ||
26 | ||
27 | Ok(json!(null)) | |
28 | } | |
29 | ||
e63e99d6 | 30 | pub fn router() -> Router { |
504b3597 | 31 | |
95b492ad | 32 | let route4 = Router::new() |
a4b7c3f2 DM |
33 | .get(ApiMethod::new( |
34 | |param, _info| { | |
fe476ce8 DM |
35 | println!("This is a clousure handler: {}", param); |
36 | ||
37 | Ok(json!(null)) | |
a4b7c3f2 DM |
38 | }, |
39 | ObjectSchema::new("Another Endpoint.")) | |
40 | .returns(Schema::Null)); | |
8a700532 | 41 | |
95b492ad DM |
42 | |
43 | let nodeinfo = Router::new() | |
d3369f81 DM |
44 | .get(ApiMethod::new( |
45 | test_sync_api_handler, | |
46 | ObjectSchema::new("This is a simple test.") | |
47 | .optional("force", BooleanSchema::new("Test for boolean options"))) | |
48 | ) | |
49 | .subdir("subdir3", route4); | |
504b3597 | 50 | |
95b492ad DM |
51 | let nodes = Router::new() |
52 | .match_all("node", nodeinfo); | |
53 | ||
95b492ad | 54 | |
6ce50400 | 55 | let route = Router::new() |
a4b7c3f2 | 56 | .get(ApiMethod::new( |
6ce50400 DM |
57 | |_,_| Ok(json!([ |
58 | {"subdir": "config"}, | |
59 | {"subdir": "version"}, | |
60 | {"subdir": "nodes"} | |
61 | ])), | |
a4b7c3f2 | 62 | ObjectSchema::new("Directory index."))) |
6ce50400 DM |
63 | .subdir("config", config::router()) |
64 | .subdir("version", version::router()) | |
d3369f81 | 65 | .subdir("nodes", nodes); |
8a700532 | 66 | |
0dde2f04 | 67 | route |
504b3597 | 68 | } |