use Arc for ApiServer

This commit is contained in:
Dietmar Maurer 2018-11-14 11:57:01 +01:00
parent 2c10fd5cb1
commit a9696f7beb
1 changed files with 15 additions and 12 deletions

View File

@ -1,6 +1,7 @@
extern crate apitest; extern crate apitest;
use failure::*; use failure::*;
use std::sync::Arc;
use std::collections::HashMap; use std::collections::HashMap;
//use std::io; //use std::io;
//use std::fs; //use std::fs;
@ -326,21 +327,23 @@ fn main() {
let addr = ([127, 0, 0, 1], 8007).into(); let addr = ([127, 0, 0, 1], 8007).into();
let new_svc = || { lazy_static!{
service_fn(|req| { static ref ALIASES: HashMap<String, PathBuf> = initialize_directory_aliases();
static ref ROUTER: MethodInfo = apitest::api3::router();
}
lazy_static!{ let api_server = Arc::new(ApiServer {
static ref ALIASES: HashMap<String, PathBuf> = initialize_directory_aliases(); basedir: "/var/www". into(),
static ref ROUTER: MethodInfo = apitest::api3::router(); router: &ROUTER,
} aliases: &ALIASES,
});
let api_server = ApiServer { let new_svc = move || {
basedir: "/var/www". into(),
router: &ROUTER,
aliases: &ALIASES,
};
handle_request(&api_server, req).then(|result| { let api = api_server.clone();
service_fn(move |req| {
handle_request(&api, req).then(|result| {
match result { match result {
Ok(res) => Ok::<_,String>(res), Ok(res) => Ok::<_,String>(res),
Err(err) => { Err(err) => {