Implements Request Limit with Redis
This commit is contained in:
@@ -8,6 +8,8 @@ pub struct ConfigAuth {
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_auth() -> ConfigAuth {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let url = env::var("AUTH_URL").expect("AUTH_URL must be set");
|
||||
|
||||
ConfigAuth { auth_url: url }
|
||||
|
||||
@@ -13,6 +13,8 @@ pub struct ConfigEmail {
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_email() -> ConfigEmail {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let server = env::var("SMTP_SERVER").expect("SMTP_SERVER must be set");
|
||||
let port = env::var("SMTP_PORT").expect("SMTP_PORT must be set");
|
||||
let username = env::var("SMTP_USERNAME").expect("SMTP_USERNAME must be set");
|
||||
|
||||
23
src/config/config_limits.rs
Normal file
23
src/config/config_limits.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use cached::proc_macro::cached;
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigLimits {
|
||||
pub max_requests: u32,
|
||||
pub expiration_time: usize,
|
||||
}
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_limits() -> ConfigLimits {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let max_requests = env::var("MAX_REQUESTS").unwrap_or("10".to_string())
|
||||
.parse::<u32>().unwrap();
|
||||
let expiration_time = env::var("EXPIRATION_TIME").unwrap_or("604800".to_string())
|
||||
.parse::<usize>().unwrap();
|
||||
|
||||
ConfigLimits {
|
||||
max_requests,
|
||||
expiration_time,
|
||||
}
|
||||
}
|
||||
24
src/config/config_redis.rs
Normal file
24
src/config/config_redis.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use cached::proc_macro::cached;
|
||||
use std::env;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConfigRedis {
|
||||
pub redis_url: String,
|
||||
pub redis_port: u16,
|
||||
pub redis_password: Option<String>,
|
||||
}
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_redis() -> ConfigRedis {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let url = env::var("REDIS_URL").unwrap_or("localhost".to_string());
|
||||
let port = env::var("REDIS_PORT").unwrap_or("6379".to_string());
|
||||
let password = env::var("REDIS_PASSWORD").ok();
|
||||
|
||||
ConfigRedis {
|
||||
redis_url: url,
|
||||
redis_port: port.parse::<u16>().unwrap(),
|
||||
redis_password: password
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ pub struct ConfigServer {
|
||||
|
||||
#[cached]
|
||||
pub fn get_config_server() -> ConfigServer {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let h = option_env!("HOST").unwrap_or("localhost").to_string();
|
||||
|
||||
let p = option_env!("PORT")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
pub mod config_auth;
|
||||
pub mod config_email;
|
||||
pub mod config_server;
|
||||
pub mod config_redis;
|
||||
pub mod config_limits;
|
||||
|
||||
Reference in New Issue
Block a user