-
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bff3def
commit 10e1eb0
Showing
6 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
examples/flash-cookie/Cargo.toml → examples/flash-cookie-store/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "example-flash-session-store" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
salvo = { path = "../../crates/salvo" } | ||
salvo-flash = { default-features = false, features = ["session-store"], path = "../../crates/flash" } | ||
salvo-session = { path = "../../crates/session" } | ||
tokio = { version = "1", features = ["macros"] } | ||
tracing = "0.1" | ||
tracing-subscriber = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::fmt::Write; | ||
|
||
use salvo::prelude::*; | ||
use salvo_flash::{SessionStore, FlashDepotExt}; | ||
|
||
#[handler] | ||
pub async fn set_flash(depot: &mut Depot, res: &mut Response) { | ||
let flash = depot.outgoing_flash_mut(); | ||
flash.info("Hey there!").debug("How is it going?"); | ||
res.render(Redirect::other("/get").unwrap()); | ||
} | ||
|
||
#[handler] | ||
pub async fn get_flash(depot: &mut Depot, _res: &mut Response) -> String { | ||
let mut body = String::new(); | ||
if let Some(flash) = depot.incoming_flash() { | ||
for message in flash.iter() { | ||
writeln!(body, "{} - {}", message.value, message.level).unwrap(); | ||
} | ||
} | ||
body | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::fmt().init(); | ||
|
||
tracing::info!("Listening on http://127.0.0.1:7878"); | ||
let session_handler = salvo_session::SessionHandler::builder( | ||
salvo_session::MemoryStore::new(), | ||
b"secretabsecretabsecretabsecretabsecretabsecretabsecretabsecretab", | ||
) | ||
.build() | ||
.unwrap(); | ||
let router = Router::new() | ||
.hoop(session_handler) | ||
.hoop(SessionStore::new().into_handler()) | ||
.push(Router::with_path("get").get(get_flash)) | ||
.push(Router::with_path("set").get(set_flash)); | ||
Server::new(TcpListener::bind("127.0.0.1:7878")).serve(router).await; | ||
} |