1
0
mirror of https://github.com/actix/examples synced 2024-11-23 14:31:07 +01:00

reduce futures dep

This commit is contained in:
Rob Ede 2022-03-06 00:15:16 +00:00
parent c5f2a8fcc7
commit e8cd22d2f2
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
25 changed files with 62 additions and 59 deletions

18
Cargo.lock generated
View File

@ -501,7 +501,6 @@ dependencies = [
"actix-cors",
"actix-web",
"env_logger",
"futures",
"serde 1.0.136",
"serde_json",
]
@ -2794,7 +2793,7 @@ version = "1.0.0"
dependencies = [
"actix-web",
"env_logger",
"futures",
"futures-util",
"json",
"serde 1.0.136",
"serde_json",
@ -2807,7 +2806,7 @@ dependencies = [
"actix-web",
"awc",
"env_logger",
"futures",
"futures-util",
"log",
"serde 1.0.136",
"serde_json",
@ -2828,7 +2827,6 @@ name = "json_error"
version = "1.0.0"
dependencies = [
"actix-web",
"failure",
"serde 1.0.136",
"serde_json",
]
@ -3251,7 +3249,6 @@ name = "mongodb"
version = "1.0.0"
dependencies = [
"actix-web",
"futures-util",
"mongodb 2.1.0",
"serde 1.0.136",
]
@ -3341,7 +3338,7 @@ dependencies = [
"actix-web",
"dotenv",
"env_logger",
"futures",
"futures-util",
"log",
"rusoto_core",
"rusoto_s3",
@ -3615,7 +3612,6 @@ dependencies = [
"actix-web",
"anyhow",
"env_logger",
"futures-util",
"log",
"openssl",
"reqwest 0.11.9",
@ -4058,7 +4054,6 @@ dependencies = [
name = "protobuf-example"
version = "1.0.0"
dependencies = [
"actix 0.13.0",
"actix-protobuf",
"actix-web",
"env_logger",
@ -5044,7 +5039,6 @@ version = "1.0.0"
dependencies = [
"actix-web",
"env_logger",
"futures",
"tokio 1.17.0",
]
@ -5068,7 +5062,6 @@ dependencies = [
"diesel",
"dotenv",
"env_logger",
"futures",
"lazy_static",
"r2d2",
"rust-argon2",
@ -5684,7 +5677,6 @@ dependencies = [
"actix-web",
"dotenv",
"env_logger",
"futures-util",
"log",
"serde 1.0.136",
"serde_json",
@ -6485,7 +6477,7 @@ dependencies = [
"actix-web-actors",
"awc",
"env_logger",
"futures",
"futures-util",
"log",
"tokio 1.17.0",
"tokio-stream",
@ -6543,7 +6535,7 @@ dependencies = [
"byteorder",
"bytes 1.1.0",
"env_logger",
"futures",
"futures-util",
"log",
"rand 0.8.5",
"serde 1.0.136",

View File

@ -7,17 +7,16 @@ edition = "2021"
actix-web = "4"
actix-identity = "0.4"
chrono = { version = "0.4.6", features = ["serde"] }
derive_more = "0.99.0"
chrono = { version = "0.4", features = ["serde"] }
derive_more = "0.99.5"
diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "r2d2", "chrono"] }
dotenv = "0.15"
env_logger = "0.9.0"
futures = "0.3.1"
env_logger = "0.9"
r2d2 = "0.8"
rust-argon2 = "1.0.0"
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sparkpost = "0.5.2"
uuid = { version = "0.8.2", features = ["serde", "v4"] }
time = "0.3.7"
rust-argon2 = "1"
lazy_static = "1.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sparkpost = "0.5"
uuid = { version = "0.8", features = ["serde", "v4"] }
time = "0.3"

View File

@ -1,8 +1,9 @@
use std::future::{ready, Ready};
use actix_identity::Identity;
use actix_web::{dev::Payload, web, Error, FromRequest, HttpRequest, HttpResponse};
use diesel::prelude::*;
use diesel::PgConnection;
use futures::future::{err, ok, Ready};
use serde::Deserialize;
use crate::errors::ServiceError;
@ -27,11 +28,12 @@ impl FromRequest for LoggedUser {
if let Ok(identity) = Identity::from_request(req, pl).into_inner() {
if let Some(user_json) = identity.identity() {
if let Ok(user) = serde_json::from_str(&user_json) {
return ok(user);
return ready(Ok(user));
}
}
}
err(ServiceError::Unauthorized.into())
ready(Err(ServiceError::Unauthorized.into()))
}
}

View File

@ -10,12 +10,8 @@ actix-session = "0.5"
dotenv = "0.15"
env_logger = "0.9"
futures-util = "0.3.7"
log = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sqlx = { version = "0.5.10", features = ["runtime-tokio-rustls", "sqlite", "offline"] }
tera = "1.5"
[dependencies.sqlx]
features = ["runtime-tokio-rustls", "sqlite", "offline"]
version = "0.5.10"

View File

@ -7,7 +7,6 @@ edition = "2021"
actix-web = { version = "4", features = ["rustls"] }
actix-cors = "0.6"
env_logger = "0.9"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
env_logger = "0.9"
futures = "0.3"

View File

@ -8,8 +8,6 @@ actix-web = "4"
diesel = { version = "1.4.8", features = ["sqlite", "r2d2"] }
dotenv = "0.15"
env_logger = "0.9.0"
failure = "0.1.8"
futures = "0.3.1"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -5,6 +5,5 @@ edition = "2021"
[dependencies]
actix-web = "4"
futures-util = "0.3.17"
mongodb = "2.0.0"
serde = { version = "1.0", features = ["derive"] }

View File

@ -9,7 +9,7 @@ actix-multipart = "0.4"
dotenv = "0.15.0"
env_logger = "0.9"
futures = "0.3.1"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
log = "0.4"
rusoto_core = "0.47.0"
rusoto_s3 = "0.47.0"

View File

@ -1,7 +1,7 @@
use crate::utils::s3::Client;
use actix_multipart::{Field, Multipart};
use actix_web::{web, web::Bytes, Error};
use futures::StreamExt;
use futures_util::StreamExt as _;
use serde::{Deserialize, Serialize};
use std::convert::From;
use std::io::Write;

View File

@ -12,6 +12,6 @@ readme = "README.md"
actix-multipart = "0.4"
actix-web = "4"
futures-util = "0.3"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
sanitize-filename = "0.3"
uuid = { version = "0.8", features = ["v4"] }

View File

@ -71,3 +71,23 @@ async fn main() -> std::io::Result<()> {
.run()
.await
}
#[cfg(test)]
mod tests {
use actix_web::test::{self, TestRequest};
use super::*;
#[actix_web::test]
async fn api_versioning() {
let app = test::init_service(create_app()).await;
let req = TestRequest::with_uri("/api/hello").insert_header(("Accept-Version", "1"));
let res = test::call_and_read_body(&app, req.to_request()).await;
assert_eq!(res, "Hello World from v1 API!");
let req = TestRequest::with_uri("/api/hello").insert_header(("Accept-Version", "2"));
let res = test::call_and_read_body(&app, req.to_request()).await;
assert_eq!(res, "Hello World from the awesome new v2 API!");
}
}

View File

@ -10,7 +10,6 @@ actix-files = "0.6"
acme-micro = "0.12"
anyhow = "1"
env_logger = "0.9"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
log = "0.4"
openssl = { version = "0.10", features = ["v110"] }
reqwest = "0.11"

View File

@ -5,6 +5,5 @@ edition = "2021"
[dependencies]
actix-web = "4"
failure = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -8,7 +8,7 @@ actix-web = "4"
awc = { version = "3.0.0-beta.21", features = ["openssl"] }
env_logger = "0.9"
futures = "0.3.1"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
log = "0.4"
serde = { version = "1.0.43", features = ["derive"] }
serde_json = "1.0.16"

View File

@ -21,7 +21,7 @@ use actix_web::{
App, Error, HttpResponse, HttpServer,
};
use awc::Client;
use futures::StreamExt;
use futures_util::StreamExt as _;
use serde::{Deserialize, Serialize};
use validator::Validate;
use validator_derive::Validate;

View File

@ -5,8 +5,9 @@ edition = "2021"
[dependencies]
actix-web = "4"
futures = "0.3"
env_logger = "0.9.0"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
json = "0.12"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
json = "0.12"

View File

@ -1,5 +1,5 @@
use actix_web::{error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
use futures::StreamExt;
use futures_util::StreamExt as _;
use json::JsonValue;
use serde::{Deserialize, Serialize};

View File

@ -8,7 +8,7 @@ actix-web = "4"
bytes = "1.1.0"
env_logger = "0.9.0"
futures-util = "0.3"
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.78"

View File

@ -4,9 +4,9 @@ version = "1.0.0"
edition = "2021"
[dependencies]
actix = "0.13"
actix-protobuf = "0.7"
actix-web = "4"
env_logger = "0.9"
log = "0.4"
prost = "0.9"

View File

@ -6,6 +6,6 @@ description = "Send a request to the server to shut it down"
[dependencies]
actix-web = "4"
env_logger = "0.9"
futures = "0.3"
tokio = { version = "1.16", features = ["signal"] }

View File

@ -1,5 +1,4 @@
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
use futures::executor;
use std::{sync::mpsc, thread};
#[get("/hello")]
@ -37,16 +36,16 @@ async fn main() -> std::io::Result<()> {
.bind(&bind)?
.run();
// clone the Server handle
// clone the server handle
let srv = server.handle();
thread::spawn(move || {
// wait for shutdown signal
rx.recv().unwrap();
// stop server gracefully
executor::block_on(srv.stop(true))
// send stop server gracefully command
srv.stop(true)
});
// run server
// run server until stopped (either by ctrl-c or stop endpoint)
server.await
}

View File

@ -21,7 +21,7 @@ actix-web-actors = "4.1"
byteorder = "1.2"
bytes = "1"
env_logger = "0.9"
futures = "0.3"
futures-util = { version = "0.3.7", default-features = false, features = ["std", "sink"] }
log = "0.4"
rand = "0.8"
serde = { version = "1", features = ["derive"] }

View File

@ -1,6 +1,6 @@
use std::{io, thread};
use futures::{SinkExt, StreamExt};
use futures_util::{SinkExt as _, StreamExt as _};
use tokio::{net::TcpStream, select, sync::mpsc};
use tokio_stream::wrappers::UnboundedReceiverStream;

View File

@ -21,7 +21,7 @@ actix-web-actors = "4.1"
awc = "3.0.0-beta.21"
env_logger = "0.9"
futures-util = { version = "0.3.7", default-features = false, features = ["std", "sink"] }
log = "0.4"
futures = "0.3.7"
tokio = { version = "1.13.1", features = ["full"] }
tokio-stream = "0.1.8"

View File

@ -4,7 +4,7 @@ use std::{io, thread};
use actix_web::web::Bytes;
use awc::ws;
use futures::{SinkExt as _, StreamExt as _};
use futures_util::{SinkExt as _, StreamExt as _};
use tokio::{select, sync::mpsc};
use tokio_stream::wrappers::UnboundedReceiverStream;