pass ApiMethod to handler

This commit is contained in:
Dietmar Maurer 2018-11-07 11:06:37 +01:00
parent ab9e6de21c
commit e72677bf50
3 changed files with 3 additions and 5 deletions

View File

@ -7,7 +7,7 @@ use crate::api_info::*;
use serde_json::{json, Value};
fn test_api_handler(param: Value) -> Result<Value, Error> {
fn test_api_handler(param: Value, info: &ApiMethod) -> Result<Value, Error> {
println!("This is a test {}", param);
// let force: Option<bool> = Some(false);

View File

@ -5,15 +5,13 @@ use serde_json::{Value};
use std::collections::HashMap;
#[derive(Debug)]
pub struct ApiMethod {
pub description: &'static str,
pub parameters: Jss,
pub returns: Jss,
pub handler: fn(Value) -> Result<Value, Error>,
pub handler: fn(Value, &ApiMethod) -> Result<Value, Error>,
}
#[derive(Debug)]
pub struct MethodInfo {
pub get: Option<ApiMethod>,
pub put: Option<ApiMethod>,

View File

@ -78,7 +78,7 @@ fn handle_request(req: Request<Body>) -> Response<Body> {
None => json!({}),
};
match (api_method.handler)(param) {
match (api_method.handler)(param, &api_method) {
Ok(res) => {
let json_str = res.to_string();
return Response::new(Body::from(json_str));