|
|
@@ -4,8 +4,7 @@ use strategy::quant::Quant;
|
|
|
use actix_web::{web, App, HttpResponse, HttpServer, Responder, post, get};
|
|
|
use actix_web::dev::Server;
|
|
|
use tokio::sync::Mutex;
|
|
|
-use tracing::debug;
|
|
|
-
|
|
|
+use tracing::{debug, info};
|
|
|
#[derive(Deserialize)]
|
|
|
#[derive(Debug)]
|
|
|
struct InputData {
|
|
|
@@ -29,13 +28,23 @@ async fn post_handler(quant_arc: web::Data<Arc<Mutex<Quant>>>, input: web::Json<
|
|
|
}
|
|
|
|
|
|
// Server要.await才能使用
|
|
|
-// pub fn run_server(port: u32, quant_arc: Arc<Mutex<Quant>>) -> Server {
|
|
|
-// return HttpServer::new(move || {
|
|
|
-// App::new()
|
|
|
-// .app_data(web::Data::new(quant_arc.clone()))
|
|
|
-// .service(get_handler)
|
|
|
-// .service(post_handler)
|
|
|
-// })
|
|
|
-// .bind(format!("127.0.0.1:{}", port))?
|
|
|
-// .run();
|
|
|
-// }
|
|
|
+pub fn run_server(port: u32, quant_arc: Arc<Mutex<Quant>>) -> Server {
|
|
|
+ let addr = format!("127.0.0.1:{}", port);
|
|
|
+ info!("中控绑定地址:{}", addr);
|
|
|
+ let bind_rst = HttpServer::new(move || {
|
|
|
+ App::new()
|
|
|
+ .app_data(web::Data::new(quant_arc.clone()))
|
|
|
+ .service(get_handler)
|
|
|
+ .service(post_handler)
|
|
|
+ })
|
|
|
+ .bind(addr);
|
|
|
+
|
|
|
+ return match bind_rst {
|
|
|
+ Ok(server) => {
|
|
|
+ server.run()
|
|
|
+ },
|
|
|
+ Err(err) => {
|
|
|
+ panic!("{}", format!("Bind port error:{}", err.to_string()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|