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 serde_json::{json, Value};
|
||||
|
||||
use futures::future::*;
|
||||
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> {
|
||||
fn test_sync_api_handler(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
|
||||
println!("This is a test {}", param);
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
let route = MethodInfo::new()
|
||||
.get(ApiMethod {
|
||||
handler: test_sync_api_handler,
|
||||
async_handler: test_async_api_handler,
|
||||
description: "This is a simple test.",
|
||||
parameters: parameter!{
|
||||
force => Boolean!{
|
||||
|
@ -1,10 +1,9 @@
|
||||
use std::fmt;
|
||||
use failure::*;
|
||||
use futures::future::*;
|
||||
|
||||
use crate::json_schema::*;
|
||||
use serde_json::{Value};
|
||||
use hyper::{Body, Response, StatusCode};
|
||||
use hyper::{StatusCode};
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -13,7 +12,6 @@ pub struct ApiMethod {
|
||||
pub parameters: Jss,
|
||||
pub returns: Jss,
|
||||
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)]
|
||||
|
@ -1,19 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::{PathBuf};
|
||||
use crate::api_info::*;
|
||||
use crate::json_schema::*;
|
||||
//use crate::json_schema::*;
|
||||
|
||||
use futures::future::{self, Either};
|
||||
|
||||
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;
|
||||
use hyper::{Method};
|
||||
|
||||
pub struct ApiServer {
|
||||
basedir: PathBuf,
|
||||
|
@ -166,7 +166,7 @@ fn parse_simple_value(value_str: &str, schema: &Jss) -> Result<Value, Error> {
|
||||
Jss::Null => {
|
||||
bail!("internal error - found Null schema.");
|
||||
}
|
||||
Jss::Boolean(jss_boolean) => {
|
||||
Jss::Boolean(_jss_boolean) => {
|
||||
let res = match value_str.to_lowercase().as_str() {
|
||||
"1" | "on" | "yes" | "true" => true,
|
||||
"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.");
|
||||
}
|
||||
}
|
||||
ApiStringFormat::Complex(ref subschema) => {
|
||||
ApiStringFormat::Complex(ref _subschema) => {
|
||||
bail!("implement me!");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user