pass ApiMethod to handler
This commit is contained in:
parent
ab9e6de21c
commit
e72677bf50
|
@ -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);
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue