1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-07-01 04:05:09 +02:00

updating example

This commit is contained in:
Stefan Puhlmann
2019-05-18 14:36:36 +02:00
parent 5ab0474781
commit 90648058b4
2 changed files with 21 additions and 21 deletions

View File

@ -1,43 +1,43 @@
extern crate bytes;
extern crate actix;
extern crate actix_web;
extern crate actix_protobuf;
extern crate actix_web;
extern crate bytes;
extern crate env_logger;
extern crate prost;
#[macro_use]
#[macro_use]
extern crate prost_derive;
use actix_web::*;
use actix_protobuf::*;
use actix_web::*;
#[derive(Clone, PartialEq, Message)]
pub struct MyObj {
#[prost(int32, tag="1")]
#[prost(int32, tag = "1")]
pub number: i32,
#[prost(string, tag="2")]
#[prost(string, tag = "2")]
pub name: String,
}
fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
println!("model: {:?}", msg);
HttpResponse::Ok().protobuf(msg.0) // <- send response
HttpResponse::Ok().protobuf(msg.0) // <- send response
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("prost-example");
server::new(|| {
HttpServer::new(|| {
App::new()
.middleware(middleware::Logger::default())
.resource("/", |r| r.method(http::Method::POST).with(index))})
.bind("127.0.0.1:8080").unwrap()
.shutdown_timeout(1)
.start();
.wrap(middleware::Logger::default())
.service(web::resource("/").route(web::post().to(index)))
})
.bind("127.0.0.1:8081")
.unwrap()
.shutdown_timeout(1)
.start();
println!("Started http server: 127.0.0.1:8080");
println!("Started http server: 127.0.0.1:8081");
let _ = sys.run();
}