2018-04-13 09:18:42 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate prost_derive;
|
|
|
|
|
2019-05-21 22:09:27 +02:00
|
|
|
use actix_protobuf::*;
|
|
|
|
use actix_web::*;
|
2018-04-13 09:18:42 +08:00
|
|
|
|
2019-05-21 22:09:27 +02:00
|
|
|
#[derive(Clone, PartialEq, Message)]
|
2018-04-13 09:18:42 +08:00
|
|
|
pub struct MyObj {
|
2018-05-08 11:08:43 -07:00
|
|
|
#[prost(int32, tag = "1")]
|
2018-04-13 09:18:42 +08:00
|
|
|
pub number: i32,
|
2020-09-12 16:49:45 +01:00
|
|
|
|
2018-05-08 11:08:43 -07:00
|
|
|
#[prost(string, tag = "2")]
|
2018-04-13 09:18:42 +08:00
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
2020-02-06 18:17:23 +01:00
|
|
|
async fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
|
2019-05-21 22:09:27 +02:00
|
|
|
println!("model: {:?}", msg);
|
|
|
|
HttpResponse::Ok().protobuf(msg.0) // <- send response
|
2018-04-13 09:18:42 +08:00
|
|
|
}
|
|
|
|
|
2020-09-12 16:49:45 +01:00
|
|
|
#[actix_web::main]
|
2020-02-06 18:17:23 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
|
std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
|
2018-04-13 09:18:42 +08:00
|
|
|
env_logger::init();
|
|
|
|
|
2019-03-30 09:12:42 -07:00
|
|
|
HttpServer::new(|| {
|
2018-04-13 09:18:42 +08:00
|
|
|
App::new()
|
2019-03-30 09:12:42 -07:00
|
|
|
.wrap(middleware::Logger::default())
|
2019-05-21 22:09:27 +02:00
|
|
|
.service(web::resource("/").route(web::post().to(index)))
|
2019-07-11 15:02:25 +06:00
|
|
|
})
|
2020-02-06 18:17:23 +01:00
|
|
|
.bind("127.0.0.1:8081")?
|
2019-05-21 22:09:27 +02:00
|
|
|
.shutdown_timeout(1)
|
2020-02-06 18:17:23 +01:00
|
|
|
.run()
|
|
|
|
.await
|
2018-04-13 09:18:42 +08:00
|
|
|
}
|