This commit is contained in:
Zynh0722 2024-02-09 05:12:24 -08:00
parent 08191238aa
commit 2b534b51a3
4 changed files with 88 additions and 2 deletions

81
Cargo.lock generated
View file

@ -468,6 +468,8 @@ dependencies = [
"riven",
"task-local-extensions",
"tokio",
"tracing",
"tracing-subscriber",
]
[[package]]
@ -530,6 +532,16 @@ dependencies = [
"tempfile",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -620,6 +632,12 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.12.1"
@ -934,6 +952,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
@ -1086,6 +1113,16 @@ dependencies = [
"syn 2.0.48",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@ -1185,9 +1222,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.48",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
@ -1195,6 +1244,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"nu-ansi-term",
"sharded-slab",
"smallvec",
"thread_local",
"tracing-core",
"tracing-log",
]
[[package]]
@ -1250,6 +1325,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcpkg"
version = "0.2.15"

View file

@ -14,3 +14,5 @@ task-local-extensions = "0.1.4"
reqwest-middleware = { git = "https://git.zynh.me/Zynh0722/reqwest-middleware.git" }
riven = { git = "https://git.zynh.me/Zynh0722/Riven.git", branch = "feat-middleware" }
tokio = { version = "1.36.0", features = ["full"] }
tracing-subscriber = "0.3.18"
tracing = "0.1.40"

View file

@ -7,6 +7,7 @@ use crate::cache::RedisMiddleware;
pub(crate) fn fetch_api() -> Result<RiotApi, Box<dyn Error>> {
dotenvy::dotenv()?;
tracing_subscriber::fmt::init();
let rg_api_key: String = std::env::var("RG_API_KEY")?;
let mut default_headers = reqwest::header::HeaderMap::new();

View file

@ -1,6 +1,7 @@
use reqwest::{Request, Response};
use reqwest_middleware::{Middleware, Next, Result};
use task_local_extensions::Extensions;
use tracing::info;
pub(crate) struct RedisMiddleware;
@ -12,9 +13,10 @@ impl Middleware for RedisMiddleware {
extensions: &mut Extensions,
next: Next<'_>,
) -> Result<Response> {
println!("Request started {:#?}", req);
info!("Request started: {}", req.url().as_str());
let res = next.run(req, extensions).await;
println!("Result: {:#?}", res);
info!("Request ended: {:?}", res.as_ref().unwrap().url().as_str());
res
}
}