mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
Fix deadlock in casbin example (#471)
Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
parent
0c316ec330
commit
1cc73366c5
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -57,6 +57,7 @@ dependencies = [
|
|||||||
"loge",
|
"loge",
|
||||||
"rhai",
|
"rhai",
|
||||||
"rhai_codegen",
|
"rhai_codegen",
|
||||||
|
"tokio 0.2.25",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -13,3 +13,4 @@ casbin = "=2.0.5"
|
|||||||
rhai = "=0.19.14"
|
rhai = "=0.19.14"
|
||||||
rhai_codegen = "=0.3.3"
|
rhai_codegen = "=0.3.3"
|
||||||
loge = {version = "0.4", default-features = false, features = ["colored", "chrono"]}
|
loge = {version = "0.4", default-features = false, features = ["colored", "chrono"]}
|
||||||
|
tokio = { version = "0.2.22", features = ["sync"] }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi};
|
use casbin::{CoreApi, DefaultModel, Enforcer, FileAdapter, RbacApi};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
|
use actix_web::{middleware, web, App, HttpRequest, HttpResponse, HttpServer};
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ async fn success(
|
|||||||
enforcer: web::Data<RwLock<Enforcer>>,
|
enforcer: web::Data<RwLock<Enforcer>>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
) -> HttpResponse {
|
) -> HttpResponse {
|
||||||
let mut e = enforcer.write().unwrap();
|
let mut e = enforcer.write().await;
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
assert_eq!(vec!["data2_admin"], e.get_roles_for_user("alice", None));
|
assert_eq!(vec!["data2_admin"], e.get_roles_for_user("alice", None));
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ async fn success(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn fail(enforcer: web::Data<RwLock<Enforcer>>, req: HttpRequest) -> HttpResponse {
|
async fn fail(enforcer: web::Data<RwLock<Enforcer>>, req: HttpRequest) -> HttpResponse {
|
||||||
let mut e = enforcer.write().unwrap();
|
let mut e = enforcer.write().await;
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
assert_eq!(vec!["data1_admin"], e.get_roles_for_user("alice", None));
|
assert_eq!(vec!["data1_admin"], e.get_roles_for_user("alice", None));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user