From 90648058b458705bb5caa22e0e6037cd1ae9cb96 Mon Sep 17 00:00:00 2001 From: Stefan Puhlmann Date: Sat, 18 May 2019 14:36:36 +0200 Subject: [PATCH] updating example --- examples/prost-example/client.py | 10 +++++----- examples/prost-example/src/main.rs | 32 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) mode change 100644 => 100755 examples/prost-example/client.py diff --git a/examples/prost-example/client.py b/examples/prost-example/client.py old mode 100644 new mode 100755 index c55f78885..1f16270f4 --- a/examples/prost-example/client.py +++ b/examples/prost-example/client.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # just start server and run client.py # wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-python-3.5.1.zip @@ -5,12 +6,11 @@ # cd protobuf-3.5.1/python/ # python3.6 setup.py install -# pip3.6 install --upgrade pip -# pip3.6 install aiohttp +# pip3 install --upgrade pip +# pip3 install aiohttp -# python3.6 client.py +# python3 client.py -#!/usr/bin/env python import test_pb2 import traceback import sys @@ -48,7 +48,7 @@ async def fetch(session): obj = test_pb2.MyObj() obj.number = 9 obj.name = 'USB' - async with session.post('http://localhost:8080/', data=obj.SerializeToString(), + async with session.post('http://127.0.0.1:8081/', data=obj.SerializeToString(), headers={"content-type": "application/protobuf"}) as resp: print(resp.status) data = await resp.read() diff --git a/examples/prost-example/src/main.rs b/examples/prost-example/src/main.rs index d61ea1402..15f7f4c88 100644 --- a/examples/prost-example/src/main.rs +++ b/examples/prost-example/src/main.rs @@ -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) -> Result { 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(); }