From 083130682f8b39568d7b0c4b46b7ce02a41909dc Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 5 Mar 2019 08:23:24 -0500 Subject: [PATCH 1/4] Remove custom rustfmt rule This commit removes the custom rustfmt rule (which specified a shorter line length) so that the project conforms to idiomatic Rust formatting standards. --- rustfmt.toml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index 866c756..0000000 --- a/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -max_width = 120 \ No newline at end of file From 7a0b11e2401be50866efc2e38b028bf959e1fab2 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 5 Mar 2019 08:49:35 -0500 Subject: [PATCH 2/4] Add descriptive success messages Improves the success messages from "OMG! It worked!" to a descriptive string identifying which function was invoked. --- src/api/http/direct.rs | 2 +- src/api/http/hashtag.rs | 4 ++-- src/api/http/list.rs | 2 +- src/api/http/public.rs | 4 ++-- src/api/http/user.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/api/http/direct.rs b/src/api/http/direct.rs index 191fa9f..63ec51e 100644 --- a/src/api/http/direct.rs +++ b/src/api/http/direct.rs @@ -2,5 +2,5 @@ use crate::AppState; use actix_web::{HttpRequest, Responder}; pub fn index(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from direct::index" } diff --git a/src/api/http/hashtag.rs b/src/api/http/hashtag.rs index 594d6a8..025785a 100644 --- a/src/api/http/hashtag.rs +++ b/src/api/http/hashtag.rs @@ -2,9 +2,9 @@ use crate::AppState; use actix_web::{HttpRequest, Responder}; pub fn index(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from hashtag::index" } pub fn local(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from hashtag::local" } diff --git a/src/api/http/list.rs b/src/api/http/list.rs index 191fa9f..bdf81ae 100644 --- a/src/api/http/list.rs +++ b/src/api/http/list.rs @@ -2,5 +2,5 @@ use crate::AppState; use actix_web::{HttpRequest, Responder}; pub fn index(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from list::index" } diff --git a/src/api/http/public.rs b/src/api/http/public.rs index 594d6a8..c59b6fe 100644 --- a/src/api/http/public.rs +++ b/src/api/http/public.rs @@ -2,9 +2,9 @@ use crate::AppState; use actix_web::{HttpRequest, Responder}; pub fn index(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from public::index" } pub fn local(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from public::local" } diff --git a/src/api/http/user.rs b/src/api/http/user.rs index 191fa9f..abd3284 100644 --- a/src/api/http/user.rs +++ b/src/api/http/user.rs @@ -2,5 +2,5 @@ use crate::AppState; use actix_web::{HttpRequest, Responder}; pub fn index(_req: HttpRequest) -> impl Responder { - "OMG! It works!" + "placeholder response from user::index" } From fffd3b6b4d4ea90b70d5a19a214f5ad929bacbe9 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 5 Mar 2019 09:19:38 -0500 Subject: [PATCH 3/4] Improve logging Add more descriptive messages for the logging triggered by the websocket server. --- src/api/ws.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/api/ws.rs b/src/api/ws.rs index c0de2cb..783d057 100644 --- a/src/api/ws.rs +++ b/src/api/ws.rs @@ -15,18 +15,26 @@ impl Actor for WebsocketActor { /// Handler for ws::Message message impl StreamHandler for WebsocketActor { fn started(&mut self, ctx: &mut Self::Context) { - ctx.run_interval(Duration::from_secs(HEARTBEAT_INTERVAL_SECONDS), |_, inner_ctx| { - inner_ctx.ping(""); - }); + ctx.run_interval( + Duration::from_secs(HEARTBEAT_INTERVAL_SECONDS), + |_, inner_ctx| { + inner_ctx.ping("Ping from StreamHandler"); + }, + ); } + // This appears to be an echo server based on the actix_web documentation + // We won't actually need echo functionality in the final server fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) { debug!("Message {:?}", msg); - let red = ctx.state().redis.send(Command(RespValue::SimpleString("GET".into()))); + let red = ctx + .state() + .redis + .send(Command(RespValue::SimpleString("GET".into()))); match msg { - ws::Message::Pong(msg) => debug!("{}", msg), + ws::Message::Pong(msg) => debug!("matched: {}", msg), ws::Message::Text(text) => ctx.text(text), _ => (), } From 4842475b18ba7b646ed1138f1988f91e24c330a4 Mon Sep 17 00:00:00 2001 From: Daniel Sockwell Date: Tue, 5 Mar 2019 09:23:44 -0500 Subject: [PATCH 4/4] Rustfmt all code Revise all code to comply with rustfmt --- src/main.rs | 6 +++++- src/middleware/mod.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index d7f74c7..b573ba1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,6 +91,10 @@ fn cors_middleware() -> Cors { Cors::build() .allowed_origin("*") .allowed_methods(vec!["GET", "OPTIONS"]) - .allowed_headers(vec![header::AUTHORIZATION, header::ACCEPT, header::CACHE_CONTROL]) + .allowed_headers(vec![ + header::AUTHORIZATION, + header::ACCEPT, + header::CACHE_CONTROL, + ]) .finish() } diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 5696e21..0e4a05d 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -1 +1 @@ -pub mod auth; \ No newline at end of file +pub mod auth;