mirror of
https://github.com/actix/examples
synced 2024-11-23 14:31:07 +01:00
reduce futures dep
This commit is contained in:
parent
c5f2a8fcc7
commit
e8cd22d2f2
18
Cargo.lock
generated
18
Cargo.lock
generated
@ -501,7 +501,6 @@ dependencies = [
|
|||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
@ -2794,7 +2793,7 @@ version = "1.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures-util",
|
||||||
"json",
|
"json",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -2807,7 +2806,7 @@ dependencies = [
|
|||||||
"actix-web",
|
"actix-web",
|
||||||
"awc",
|
"awc",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -2828,7 +2827,6 @@ name = "json_error"
|
|||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"failure",
|
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
@ -3251,7 +3249,6 @@ name = "mongodb"
|
|||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"futures-util",
|
|
||||||
"mongodb 2.1.0",
|
"mongodb 2.1.0",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
]
|
]
|
||||||
@ -3341,7 +3338,7 @@ dependencies = [
|
|||||||
"actix-web",
|
"actix-web",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"rusoto_core",
|
"rusoto_core",
|
||||||
"rusoto_s3",
|
"rusoto_s3",
|
||||||
@ -3615,7 +3612,6 @@ dependencies = [
|
|||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-util",
|
|
||||||
"log",
|
"log",
|
||||||
"openssl",
|
"openssl",
|
||||||
"reqwest 0.11.9",
|
"reqwest 0.11.9",
|
||||||
@ -4058,7 +4054,6 @@ dependencies = [
|
|||||||
name = "protobuf-example"
|
name = "protobuf-example"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix 0.13.0",
|
|
||||||
"actix-protobuf",
|
"actix-protobuf",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
@ -5044,7 +5039,6 @@ version = "1.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
|
||||||
"tokio 1.17.0",
|
"tokio 1.17.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -5068,7 +5062,6 @@ dependencies = [
|
|||||||
"diesel",
|
"diesel",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"r2d2",
|
"r2d2",
|
||||||
"rust-argon2",
|
"rust-argon2",
|
||||||
@ -5684,7 +5677,6 @@ dependencies = [
|
|||||||
"actix-web",
|
"actix-web",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures-util",
|
|
||||||
"log",
|
"log",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@ -6485,7 +6477,7 @@ dependencies = [
|
|||||||
"actix-web-actors",
|
"actix-web-actors",
|
||||||
"awc",
|
"awc",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"tokio 1.17.0",
|
"tokio 1.17.0",
|
||||||
"tokio-stream",
|
"tokio-stream",
|
||||||
@ -6543,7 +6535,7 @@ dependencies = [
|
|||||||
"byteorder",
|
"byteorder",
|
||||||
"bytes 1.1.0",
|
"bytes 1.1.0",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"futures",
|
"futures-util",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"serde 1.0.136",
|
"serde 1.0.136",
|
||||||
|
@ -7,17 +7,16 @@ edition = "2021"
|
|||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
actix-identity = "0.4"
|
actix-identity = "0.4"
|
||||||
|
|
||||||
chrono = { version = "0.4.6", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
derive_more = "0.99.0"
|
derive_more = "0.99.5"
|
||||||
diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "r2d2", "chrono"] }
|
diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "r2d2", "chrono"] }
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9"
|
||||||
futures = "0.3.1"
|
|
||||||
r2d2 = "0.8"
|
r2d2 = "0.8"
|
||||||
rust-argon2 = "1.0.0"
|
rust-argon2 = "1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1"
|
||||||
sparkpost = "0.5.2"
|
sparkpost = "0.5"
|
||||||
uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
uuid = { version = "0.8", features = ["serde", "v4"] }
|
||||||
time = "0.3.7"
|
time = "0.3"
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
use std::future::{ready, Ready};
|
||||||
|
|
||||||
use actix_identity::Identity;
|
use actix_identity::Identity;
|
||||||
use actix_web::{dev::Payload, web, Error, FromRequest, HttpRequest, HttpResponse};
|
use actix_web::{dev::Payload, web, Error, FromRequest, HttpRequest, HttpResponse};
|
||||||
use diesel::prelude::*;
|
use diesel::prelude::*;
|
||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use futures::future::{err, ok, Ready};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::errors::ServiceError;
|
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 Ok(identity) = Identity::from_request(req, pl).into_inner() {
|
||||||
if let Some(user_json) = identity.identity() {
|
if let Some(user_json) = identity.identity() {
|
||||||
if let Ok(user) = serde_json::from_str(&user_json) {
|
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()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,12 +10,8 @@ actix-session = "0.5"
|
|||||||
|
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures-util = "0.3.7"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
sqlx = { version = "0.5.10", features = ["runtime-tokio-rustls", "sqlite", "offline"] }
|
||||||
tera = "1.5"
|
tera = "1.5"
|
||||||
|
|
||||||
[dependencies.sqlx]
|
|
||||||
features = ["runtime-tokio-rustls", "sqlite", "offline"]
|
|
||||||
version = "0.5.10"
|
|
||||||
|
@ -7,7 +7,6 @@ edition = "2021"
|
|||||||
actix-web = { version = "4", features = ["rustls"] }
|
actix-web = { version = "4", features = ["rustls"] }
|
||||||
actix-cors = "0.6"
|
actix-cors = "0.6"
|
||||||
|
|
||||||
|
env_logger = "0.9"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
env_logger = "0.9"
|
|
||||||
futures = "0.3"
|
|
||||||
|
@ -8,8 +8,6 @@ actix-web = "4"
|
|||||||
diesel = { version = "1.4.8", features = ["sqlite", "r2d2"] }
|
diesel = { version = "1.4.8", features = ["sqlite", "r2d2"] }
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
failure = "0.1.8"
|
|
||||||
futures = "0.3.1"
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -5,6 +5,5 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
futures-util = "0.3.17"
|
|
||||||
mongodb = "2.0.0"
|
mongodb = "2.0.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
@ -9,7 +9,7 @@ actix-multipart = "0.4"
|
|||||||
|
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures = "0.3.1"
|
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rusoto_core = "0.47.0"
|
rusoto_core = "0.47.0"
|
||||||
rusoto_s3 = "0.47.0"
|
rusoto_s3 = "0.47.0"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::utils::s3::Client;
|
use crate::utils::s3::Client;
|
||||||
use actix_multipart::{Field, Multipart};
|
use actix_multipart::{Field, Multipart};
|
||||||
use actix_web::{web, web::Bytes, Error};
|
use actix_web::{web, web::Bytes, Error};
|
||||||
use futures::StreamExt;
|
use futures_util::StreamExt as _;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
@ -12,6 +12,6 @@ readme = "README.md"
|
|||||||
actix-multipart = "0.4"
|
actix-multipart = "0.4"
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
|
|
||||||
futures-util = "0.3"
|
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||||
sanitize-filename = "0.3"
|
sanitize-filename = "0.3"
|
||||||
uuid = { version = "0.8", features = ["v4"] }
|
uuid = { version = "0.8", features = ["v4"] }
|
||||||
|
@ -71,3 +71,23 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.run()
|
.run()
|
||||||
.await
|
.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!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -10,7 +10,6 @@ actix-files = "0.6"
|
|||||||
acme-micro = "0.12"
|
acme-micro = "0.12"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
openssl = { version = "0.10", features = ["v110"] }
|
openssl = { version = "0.10", features = ["v110"] }
|
||||||
reqwest = "0.11"
|
reqwest = "0.11"
|
||||||
|
@ -5,6 +5,5 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
failure = "0.1"
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
@ -8,7 +8,7 @@ actix-web = "4"
|
|||||||
awc = { version = "3.0.0-beta.21", features = ["openssl"] }
|
awc = { version = "3.0.0-beta.21", features = ["openssl"] }
|
||||||
|
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures = "0.3.1"
|
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
serde = { version = "1.0.43", features = ["derive"] }
|
serde = { version = "1.0.43", features = ["derive"] }
|
||||||
serde_json = "1.0.16"
|
serde_json = "1.0.16"
|
||||||
|
@ -21,7 +21,7 @@ use actix_web::{
|
|||||||
App, Error, HttpResponse, HttpServer,
|
App, Error, HttpResponse, HttpServer,
|
||||||
};
|
};
|
||||||
use awc::Client;
|
use awc::Client;
|
||||||
use futures::StreamExt;
|
use futures_util::StreamExt as _;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
use validator_derive::Validate;
|
use validator_derive::Validate;
|
||||||
|
@ -5,8 +5,9 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
futures = "0.3"
|
|
||||||
env_logger = "0.9.0"
|
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 = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
json = "0.12"
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use actix_web::{error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
use actix_web::{error, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer};
|
||||||
use futures::StreamExt;
|
use futures_util::StreamExt as _;
|
||||||
use json::JsonValue;
|
use json::JsonValue;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ actix-web = "4"
|
|||||||
|
|
||||||
bytes = "1.1.0"
|
bytes = "1.1.0"
|
||||||
env_logger = "0.9.0"
|
env_logger = "0.9.0"
|
||||||
futures-util = "0.3"
|
futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0.78"
|
serde_json = "1.0.78"
|
||||||
|
@ -4,9 +4,9 @@ version = "1.0.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.13"
|
|
||||||
actix-protobuf = "0.7"
|
actix-protobuf = "0.7"
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
|
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
prost = "0.9"
|
prost = "0.9"
|
||||||
|
@ -6,6 +6,6 @@ description = "Send a request to the server to shut it down"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4"
|
||||||
|
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures = "0.3"
|
|
||||||
tokio = { version = "1.16", features = ["signal"] }
|
tokio = { version = "1.16", features = ["signal"] }
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
use actix_web::{get, middleware, post, web, App, HttpResponse, HttpServer};
|
||||||
use futures::executor;
|
|
||||||
use std::{sync::mpsc, thread};
|
use std::{sync::mpsc, thread};
|
||||||
|
|
||||||
#[get("/hello")]
|
#[get("/hello")]
|
||||||
@ -37,16 +36,16 @@ async fn main() -> std::io::Result<()> {
|
|||||||
.bind(&bind)?
|
.bind(&bind)?
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// clone the Server handle
|
// clone the server handle
|
||||||
let srv = server.handle();
|
let srv = server.handle();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
// wait for shutdown signal
|
// wait for shutdown signal
|
||||||
rx.recv().unwrap();
|
rx.recv().unwrap();
|
||||||
|
|
||||||
// stop server gracefully
|
// send stop server gracefully command
|
||||||
executor::block_on(srv.stop(true))
|
srv.stop(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
// run server
|
// run server until stopped (either by ctrl-c or stop endpoint)
|
||||||
server.await
|
server.await
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ actix-web-actors = "4.1"
|
|||||||
byteorder = "1.2"
|
byteorder = "1.2"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
futures = "0.3"
|
futures-util = { version = "0.3.7", default-features = false, features = ["std", "sink"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{io, thread};
|
use std::{io, thread};
|
||||||
|
|
||||||
use futures::{SinkExt, StreamExt};
|
use futures_util::{SinkExt as _, StreamExt as _};
|
||||||
use tokio::{net::TcpStream, select, sync::mpsc};
|
use tokio::{net::TcpStream, select, sync::mpsc};
|
||||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ actix-web-actors = "4.1"
|
|||||||
awc = "3.0.0-beta.21"
|
awc = "3.0.0-beta.21"
|
||||||
|
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
|
futures-util = { version = "0.3.7", default-features = false, features = ["std", "sink"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
futures = "0.3.7"
|
|
||||||
tokio = { version = "1.13.1", features = ["full"] }
|
tokio = { version = "1.13.1", features = ["full"] }
|
||||||
tokio-stream = "0.1.8"
|
tokio-stream = "0.1.8"
|
||||||
|
@ -4,7 +4,7 @@ use std::{io, thread};
|
|||||||
|
|
||||||
use actix_web::web::Bytes;
|
use actix_web::web::Bytes;
|
||||||
use awc::ws;
|
use awc::ws;
|
||||||
use futures::{SinkExt as _, StreamExt as _};
|
use futures_util::{SinkExt as _, StreamExt as _};
|
||||||
use tokio::{select, sync::mpsc};
|
use tokio::{select, sync::mpsc};
|
||||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user