1 个不稳定版本
0.1.2 | 2024年7月8日 |
---|---|
0.1.1 |
|
0.1.0 |
|
#703 在 算法
14KB
263 行
Throttle Lock
Throttle是一个活动计数器,可用于监控和限制活动,如传入连接和登录尝试。
免责声明:本库不保证,也不保证适用于特定目的。此代码不能替代专用的安全软件和硬件。仅用于演示目的。
示例
限制每秒调用API的次数为5次,或者锁定一分钟
use throttle_lock::Throttle;
let mut counter = Throttle::new(1000, 5, 1000*60);
if counter.is_throttled() {
println!("Try again later")
}
限制每分钟登录尝试次数为5次,或者锁定5分钟。
use throttle_lock::ThrottleHash;
let mut counter = ThrottleHash::new(60*1000, 5, 3*60*1000);
let email:String = "[email protected]".to_string();
if counter.is_throttled(&email) {
println!("Try again later")
}
lib.rs
:
Throttle Lock是一个活动计数器,可用于监控和限制活动,如传入连接和登录尝试。
示例
限制每秒调用API的次数为5次,或者锁定一分钟
use throttle_lock::Throttle;
let mut counter = Throttle::new(1000, 5, 1000*60);
if counter.is_throttled() {
println!("Try again later")
}
限制每分钟登录尝试次数为5次,或者锁定5分钟。
use throttle_lock::ThrottleHash;
let mut counter = ThrottleHash::new(60*1000, 5, 3*60*1000);
let email:String = "[email protected]".to_string();
if counter.is_throttled(&email) {
println!("Try again later")
}