1
0
mirror of https://github.com/actix/examples synced 2025-02-23 09:43:03 +01:00
Elliot Jackson 443b8197ed
Update protobuf to actix-web 2.0.0 (#249)
* Update to actix-web 2.0.0

* Add README.md
2020-02-07 02:17:23 +09:00

35 lines
811 B
Rust

#[macro_use]
extern crate prost_derive;
use actix_protobuf::*;
use actix_web::*;
#[derive(Clone, PartialEq, Message)]
pub struct MyObj {
#[prost(int32, tag = "1")]
pub number: i32,
#[prost(string, tag = "2")]
pub name: String,
}
async fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
println!("model: {:?}", msg);
HttpResponse::Ok().protobuf(msg.0) // <- send response
}
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
env_logger::init();
HttpServer::new(|| {
App::new()
.wrap(middleware::Logger::default())
.service(web::resource("/").route(web::post().to(index)))
})
.bind("127.0.0.1:8081")?
.shutdown_timeout(1)
.run()
.await
}