hadead-0.1.2 doesn't have any documentation.
๐ Had
Redis Rate Limiter with Crypto Wallets as the Unique Identifier.
Make sure that you've filled up the env vars inside .env file, also make sure you've installed the wallexerr crate using cargo add wallexerr.
๐ Run
cargo run --bin had
๐ฆ Publish
cargo login
cargo publish --dry-run
cargo publish
๐งช Test
use hadead::*;
use once_cell::sync::Lazy;
pub static HADEAD: Lazy<Config> = Lazy::new(||{
let redis_password = "REDIS_PASSWORD".to_string();
let redis_username = "REDIS_USERNAME".to_string();
let redis_host = "REDIS_HOST".to_string();
let redis_port = "REDIS_PORT".to_string();
let chill_zone_duration_in_seconds = 5;
let hadead_instance = hadead::Config{
redis_host,
redis_port,
redis_password: Some(redis_password),
redis_username: None,
chill_zone_duration_in_seconds,
id: None
};
hadead_instance
});
pub async fn api() -> Result<actix_web::HttpResponse, actix_web::Error>{
let hadead = HADEAD.clone();
let check_rate_limited = hadead.check(hadead.id.as_ref().unwrap()).await;
let Ok(flag) = check_rate_limited else{
let why = check_rate_limited.unwrap_err();
return Ok(
HttpResponse::NotAcceptable().json(why.to_string())
);
};
if flag{
return Ok(
HttpResponse::NotAcceptable().json("rate limited")
);
} else{
return Ok(
HttpResponse::Ok().json("json data")
);
}
}