remove more test code, cleanups
This commit is contained in:
parent
98d82428b0
commit
08bd8d476a
53
src/api3.rs
53
src/api3.rs
|
@ -6,15 +6,7 @@ use crate::json_schema::*;
|
||||||
use crate::api_info::*;
|
use crate::api_info::*;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
|
||||||
use futures::future::*;
|
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||||
use tokio::prelude::*;
|
|
||||||
use tokio::fs::File;
|
|
||||||
use tokio::io;
|
|
||||||
use tokio_codec;
|
|
||||||
|
|
||||||
use hyper::{Method, Body, Request, Response, Server, StatusCode};
|
|
||||||
|
|
||||||
fn test_sync_api_handler(param: Value, info: &ApiMethod) -> Result<Value, Error> {
|
|
||||||
println!("This is a test {}", param);
|
println!("This is a test {}", param);
|
||||||
|
|
||||||
// let force: Option<bool> = Some(false);
|
// let force: Option<bool> = Some(false);
|
||||||
|
@ -32,54 +24,11 @@ fn test_sync_api_handler(param: Value, info: &ApiMethod) -> Result<Value, Error>
|
||||||
Ok(json!(null))
|
Ok(json!(null))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_async_api_handler(
|
|
||||||
param: Value,
|
|
||||||
info: &ApiMethod
|
|
||||||
) -> Box<Future<Item = Response<Body>, Error = Error> + Send> {
|
|
||||||
println!("This is a test {}", param);
|
|
||||||
|
|
||||||
let task = lazy(|| {
|
|
||||||
println!("A LAZY TASK");
|
|
||||||
|
|
||||||
|
|
||||||
let dump_file = File::open("/etc/network/interfaces")
|
|
||||||
.and_then(|file| {
|
|
||||||
let file = std::io::BufReader::new(file);
|
|
||||||
let mut linenr = 1;
|
|
||||||
tokio::io::lines(file).for_each(move |line| {
|
|
||||||
println!("LINE {}: {}", linenr, line);
|
|
||||||
linenr += 1;
|
|
||||||
ok(())
|
|
||||||
})
|
|
||||||
}).map_err(|err| ());
|
|
||||||
|
|
||||||
//tokio::spawn(dump_file);
|
|
||||||
|
|
||||||
let dump_file2 = File::open("/etc/network/interfaces")
|
|
||||||
.and_then(|file| {
|
|
||||||
tokio_codec::FramedRead::new(file, tokio_codec::BytesCodec::new()).for_each(|data| {
|
|
||||||
println!("DATA {:?}", data);
|
|
||||||
ok(())
|
|
||||||
})
|
|
||||||
}).map_err(|err| ()); // fixme: log error
|
|
||||||
|
|
||||||
tokio::spawn(dump_file2);
|
|
||||||
|
|
||||||
let mut resp = Response::new(Body::from("A LAZY TASKs RESPONSE"));
|
|
||||||
*resp.status_mut() = StatusCode::OK;
|
|
||||||
|
|
||||||
ok(resp)
|
|
||||||
});
|
|
||||||
|
|
||||||
Box::new(task)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn router() -> MethodInfo {
|
pub fn router() -> MethodInfo {
|
||||||
|
|
||||||
let route = MethodInfo::new()
|
let route = MethodInfo::new()
|
||||||
.get(ApiMethod {
|
.get(ApiMethod {
|
||||||
handler: test_sync_api_handler,
|
handler: test_sync_api_handler,
|
||||||
async_handler: test_async_api_handler,
|
|
||||||
description: "This is a simple test.",
|
description: "This is a simple test.",
|
||||||
parameters: parameter!{
|
parameters: parameter!{
|
||||||
force => Boolean!{
|
force => Boolean!{
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use failure::*;
|
use failure::*;
|
||||||
use futures::future::*;
|
|
||||||
|
|
||||||
use crate::json_schema::*;
|
use crate::json_schema::*;
|
||||||
use serde_json::{Value};
|
use serde_json::{Value};
|
||||||
use hyper::{Body, Response, StatusCode};
|
use hyper::{StatusCode};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -13,7 +12,6 @@ pub struct ApiMethod {
|
||||||
pub parameters: Jss,
|
pub parameters: Jss,
|
||||||
pub returns: Jss,
|
pub returns: Jss,
|
||||||
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
|
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
|
||||||
pub async_handler: fn(Value, &ApiMethod) -> Box<Future<Item = Response<Body>, Error = Error> + Send>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Fail)]
|
#[derive(Debug, Fail)]
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::{PathBuf};
|
use std::path::{PathBuf};
|
||||||
use crate::api_info::*;
|
use crate::api_info::*;
|
||||||
use crate::json_schema::*;
|
//use crate::json_schema::*;
|
||||||
|
|
||||||
use futures::future::{self, Either};
|
use hyper::{Method};
|
||||||
|
|
||||||
use tokio::fs::File;
|
|
||||||
use tokio_codec;
|
|
||||||
|
|
||||||
|
|
||||||
use hyper::http::request::Parts;
|
|
||||||
use hyper::{Method, Body, Request, Response, Server, StatusCode};
|
|
||||||
use hyper::rt::{Future, Stream};
|
|
||||||
use hyper::service::{service_fn, NewService};
|
|
||||||
use hyper::header;
|
|
||||||
|
|
||||||
pub struct ApiServer {
|
pub struct ApiServer {
|
||||||
basedir: PathBuf,
|
basedir: PathBuf,
|
||||||
|
|
|
@ -166,7 +166,7 @@ fn parse_simple_value(value_str: &str, schema: &Jss) -> Result<Value, Error> {
|
||||||
Jss::Null => {
|
Jss::Null => {
|
||||||
bail!("internal error - found Null schema.");
|
bail!("internal error - found Null schema.");
|
||||||
}
|
}
|
||||||
Jss::Boolean(jss_boolean) => {
|
Jss::Boolean(_jss_boolean) => {
|
||||||
let res = match value_str.to_lowercase().as_str() {
|
let res = match value_str.to_lowercase().as_str() {
|
||||||
"1" | "on" | "yes" | "true" => true,
|
"1" | "on" | "yes" | "true" => true,
|
||||||
"0" | "off" | "no" | "false" => false,
|
"0" | "off" | "no" | "false" => false,
|
||||||
|
@ -219,7 +219,7 @@ fn parse_simple_value(value_str: &str, schema: &Jss) -> Result<Value, Error> {
|
||||||
bail!("value is not defined in the enumeration.");
|
bail!("value is not defined in the enumeration.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ApiStringFormat::Complex(ref subschema) => {
|
ApiStringFormat::Complex(ref _subschema) => {
|
||||||
bail!("implement me!");
|
bail!("implement me!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue