mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-11 12:31:25 +01:00
Fix minor issues in some examples (#806)
* remove unused `axum`'s dependency:`tokio-util` * fix `examples/todos`'s `async fn todos_index` iter_overeager_cloned * Add docs to `/examples/async-graphql`, just like other xamples. * remove `examples/async-graphql` unused dependencies `tracing-subscriber` and `trace` * `examples/chat` deps `trace` and `tracing-subscriber` never be used. Add trace `debug` to `chat` * remove `examples/print-request-response` unused dependency `axum-extra` * remove `examples/prometheus-metrics` unused dependency `axum-extra` * remove `examples/reverse-proxy` unused dependencies `tracing-subscriber` and `trace` * `examples/chat` fmt fix
This commit is contained in:
parent
094fd71d1a
commit
768d8a8218
6 changed files with 17 additions and 9 deletions
|
@ -7,7 +7,5 @@ publish = false
|
|||
[dependencies]
|
||||
axum = { path = "../../axum" }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
async-graphql = "3.0"
|
||||
slab = "0.4.3"
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
//! Example async-graphql application.
|
||||
//!
|
||||
//! Run with
|
||||
//!
|
||||
//! ```not_rust
|
||||
//! cargo run -p example-async-graphql
|
||||
//! ```
|
||||
|
||||
mod starwars;
|
||||
|
||||
use async_graphql::{
|
||||
|
|
|
@ -31,6 +31,12 @@ struct AppState {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Set the RUST_LOG, if it hasn't been explicitly defined
|
||||
if std::env::var_os("RUST_LOG").is_none() {
|
||||
std::env::set_var("RUST_LOG", "example_chat=trace")
|
||||
}
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let user_set = Mutex::new(HashSet::new());
|
||||
let (tx, _rx) = broadcast::channel(100);
|
||||
|
||||
|
@ -42,7 +48,7 @@ async fn main() {
|
|||
.layer(Extension(app_state));
|
||||
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
|
||||
tracing::debug!("listening on {}", addr);
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
|
@ -62,7 +68,6 @@ async fn websocket(stream: WebSocket, state: Arc<AppState>) {
|
|||
|
||||
// Username gets set in the receive loop, if it's valid.
|
||||
let mut username = String::new();
|
||||
|
||||
// Loop until a text message is found.
|
||||
while let Some(Ok(message)) = receiver.next().await {
|
||||
if let Message::Text(name) = message {
|
||||
|
@ -88,6 +93,7 @@ async fn websocket(stream: WebSocket, state: Arc<AppState>) {
|
|||
|
||||
// Send joined message to all subscribers.
|
||||
let msg = format!("{} joined.", username);
|
||||
tracing::debug!("{}", msg);
|
||||
let _ = state.tx.send(msg);
|
||||
|
||||
// This task will receive broadcast messages and send text message to our client.
|
||||
|
@ -120,8 +126,8 @@ async fn websocket(stream: WebSocket, state: Arc<AppState>) {
|
|||
|
||||
// Send user left message.
|
||||
let msg = format!("{} left.", username);
|
||||
tracing::debug!("{}", msg);
|
||||
let _ = state.tx.send(msg);
|
||||
|
||||
// Remove username from map so new clients can take it.
|
||||
state.user_set.lock().unwrap().remove(&username);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
axum = { path = "../../axum" }
|
||||
axum-extra = { path = "../../axum-extra" }
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version="0.3", features = ["env-filter"] }
|
||||
|
|
|
@ -6,7 +6,6 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
axum = { path = "../../axum" }
|
||||
axum-extra = { path = "../../axum-extra" }
|
||||
metrics = "0.18"
|
||||
metrics-exporter-prometheus = "0.8"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
|
|
|
@ -7,5 +7,3 @@ edition = "2018"
|
|||
axum = { path = "../../axum" }
|
||||
hyper = { version = "0.14", features = ["full"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version="0.3", features = ["env-filter"] }
|
||||
|
|
Loading…
Reference in a new issue