From 248cb51862562a9d4c35b2afaf47b29ff4dcf224 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 22 Jan 2019 13:56:27 +0100 Subject: [PATCH] add missing api2.rs --- src/api2.rs | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/api2.rs diff --git a/src/api2.rs b/src/api2.rs new file mode 100644 index 00000000..b9a76456 --- /dev/null +++ b/src/api2.rs @@ -0,0 +1,71 @@ +use failure::*; + +use crate::api::schema::*; +use crate::api::router::*; +use serde_json::{json, Value}; + +pub mod config; +pub mod admin; +mod version; +mod subscription; + +fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result { + println!("This is a test {}", param); + + // let force: Option = Some(false); + + //if let Some(force) = param.force { + //} + + let _force = param["force"].as_bool() + .ok_or_else(|| format_err!("missing parameter 'force'"))?; + + if let Some(_force) = param["force"].as_bool() { + } + + Ok(json!(null)) +} + +pub fn router() -> Router { + + let route4 = Router::new() + .get(ApiMethod::new( + |param, _info| { + println!("This is a clousure handler: {}", param); + + Ok(json!(null)) + }, + ObjectSchema::new("Another Endpoint.")) + .returns(Schema::Null)); + + + let nodeinfo = Router::new() + .get(ApiMethod::new( + test_sync_api_handler, + ObjectSchema::new("This is a simple test.") + .optional("force", BooleanSchema::new("Test for boolean options"))) + ) + .subdir("subdir3", route4); + + let nodes = Router::new() + .match_all("node", nodeinfo); + + + let route = Router::new() + .get(ApiMethod::new( + |_,_| Ok(json!([ + {"subdir": "config"}, + {"subdir": "admin"}, + {"subdir": "nodes"}, + {"subdir": "subscription"}, + {"subdir": "version"}, + ])), + ObjectSchema::new("Directory index."))) + .subdir("admin", admin::router()) + .subdir("config", config::router()) + .subdir("nodes", nodes) + .subdir("subscription", subscription::router()) + .subdir("version", version::router()); + + route +}