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

Migrate to actix-web v2

This commit is contained in:
Yuki Okushi
2020-01-02 03:40:29 +09:00
parent 342c711bad
commit 0eeda4c398
4 changed files with 77 additions and 75 deletions

View File

@@ -1,7 +1,8 @@
[package]
name = "prost-example"
version = "0.3.0"
authors = ["kingxsp <jin.hb.zh@outlook.com>"]
version = "0.4.0"
edition = "2018"
authors = ["kingxsp <jin.hb.zh@outlook.com>, Yuki Okushi <huyuumi.dev@gmail.com>"]
[dependencies]
bytes = "0.4"
@@ -10,6 +11,7 @@ env_logger = "*"
prost = "0.5.0"
prost-derive = "0.5.0"
actix = "0.8.1"
actix-web = "1.0.0-rc"
actix = "0.9"
actix-rt = "1"
actix-web = "2"
actix-protobuf = { path="../../" }

View File

@@ -1,9 +1,3 @@
extern crate actix;
extern crate actix_protobuf;
extern crate actix_web;
extern crate bytes;
extern crate env_logger;
extern crate prost;
#[macro_use]
extern crate prost_derive;
@@ -18,25 +12,23 @@ pub struct MyObj {
pub name: String,
}
fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
async fn index(msg: ProtoBuf<MyObj>) -> Result<HttpResponse> {
println!("model: {:?}", msg);
HttpResponse::Ok().protobuf(msg.0) // <- send response
}
fn main() {
::std::env::set_var("RUST_LOG", "actix_web=info");
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
env_logger::init();
let sys = actix::System::new("prost-example");
HttpServer::new(|| {
App::new()
.wrap(middleware::Logger::default())
.service(web::resource("/").route(web::post().to(index)))
}).bind("127.0.0.1:8081")
.unwrap()
})
.bind("127.0.0.1:8081")?
.shutdown_timeout(1)
.start();
println!("Started http server: 127.0.0.1:8081");
let _ = sys.run();
.run()
.await
}