1
0
mirror of https://github.com/actix/examples synced 2024-11-23 22:41:07 +01:00

Update session/cookie-session to v4 (#493)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Luca Palmieri 2022-02-02 15:22:50 +00:00 committed by GitHub
parent 06b024d6fe
commit 6e5b04c570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 8 deletions

View File

@ -4,6 +4,7 @@ version = "1.0.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
actix-web = "3" actix-web = "4.0.0-beta.21"
actix-session = "0.4" actix-session = "0.5.0-beta.7"
env_logger = "0.8" log = "0.4"
env_logger = "0.9.0"

View File

@ -10,16 +10,16 @@ use actix_web::{middleware::Logger, web, App, HttpRequest, HttpServer, Result};
/// simple index handler with session /// simple index handler with session
async fn index(session: Session, req: HttpRequest) -> Result<&'static str> { async fn index(session: Session, req: HttpRequest) -> Result<&'static str> {
println!("{:?}", req); log::info!("{:?}", req);
// RequestSession trait is used for session access // RequestSession trait is used for session access
let mut counter = 1; let mut counter = 1;
if let Some(count) = session.get::<i32>("counter")? { if let Some(count) = session.get::<i32>("counter")? {
println!("SESSION value: {}", count); log::info!("SESSION value: {}", count);
counter = count + 1; counter = count + 1;
session.set("counter", counter)?; session.insert("counter", counter)?;
} else { } else {
session.set("counter", counter)?; session.insert("counter", counter)?;
} }
Ok("welcome!") Ok("welcome!")
@ -29,7 +29,7 @@ async fn index(session: Session, req: HttpRequest) -> Result<&'static str> {
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info"); std::env::set_var("RUST_LOG", "actix_web=info");
env_logger::init(); env_logger::init();
println!("Starting http server: 127.0.0.1:8080"); log::info!("Starting http server: 127.0.0.1:8080");
HttpServer::new(|| { HttpServer::new(|| {
App::new() App::new()