mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-25 23:48:21 -05:00
✨ feat: add code to parse the new config option (#203)
This commit is contained in:
parent
d451fddf49
commit
4eb75a8cb1
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use crate::handler::paths::{file_path, FileType};
|
use crate::handler::paths::{file_path, FileType};
|
||||||
|
|
||||||
use super::parser_models::Style;
|
use super::parser_models::{AggregatorConfig, RateLimiter, Style};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use rlua::Lua;
|
use rlua::Lua;
|
||||||
use std::{collections::HashMap, fs, thread::available_parallelism};
|
use std::{collections::HashMap, fs, thread::available_parallelism};
|
||||||
@ -35,17 +35,7 @@ pub struct Config {
|
|||||||
pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
|
pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
|
||||||
pub request_timeout: u8,
|
pub request_timeout: u8,
|
||||||
pub threads: u8,
|
pub threads: u8,
|
||||||
}
|
pub rate_limter: RateLimiter,
|
||||||
|
|
||||||
/// Configuration options for the aggregator.
|
|
||||||
///
|
|
||||||
/// # Fields
|
|
||||||
///
|
|
||||||
/// * `random_delay` - It stores the option to whether enable or disable random delays between
|
|
||||||
/// requests.
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct AggregatorConfig {
|
|
||||||
pub random_delay: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -88,6 +78,8 @@ impl Config {
|
|||||||
parsed_threads
|
parsed_threads
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let rate_limter = globals.get::<_,HashMap<String, u8>>("rate_limiter")?;
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
port: globals.get::<_, u16>("port")?,
|
port: globals.get::<_, u16>("port")?,
|
||||||
binding_ip: globals.get::<_, String>("binding_ip")?,
|
binding_ip: globals.get::<_, String>("binding_ip")?,
|
||||||
@ -109,6 +101,10 @@ impl Config {
|
|||||||
.collect(),
|
.collect(),
|
||||||
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
||||||
threads,
|
threads,
|
||||||
|
rate_limter: RateLimiter {
|
||||||
|
number_of_requests: rate_limter["number_of_requests"],
|
||||||
|
time_limit: rate_limter["time_limit"],
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -36,3 +36,26 @@ impl Style {
|
|||||||
Style { theme, colorscheme }
|
Style { theme, colorscheme }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Configuration options for the aggregator.
|
||||||
|
///
|
||||||
|
/// # Fields
|
||||||
|
///
|
||||||
|
/// * `random_delay` - It stores the option to whether enable or disable random delays between
|
||||||
|
/// requests.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct AggregatorConfig {
|
||||||
|
pub random_delay: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Configuration options for the rate limter middleware.
|
||||||
|
///
|
||||||
|
/// # Fields
|
||||||
|
///
|
||||||
|
/// * `number_of_requests` -
|
||||||
|
/// * `time_limit` -
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct RateLimiter {
|
||||||
|
pub number_of_requests: u8,
|
||||||
|
pub time_limit: u8,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user