neon_arch commited on
Commit
4eb75a8
1 Parent(s): d451fdd

✨ feat: add code to parse the new config option (#203)

Browse files
Files changed (2) hide show
  1. src/config/parser.rs +8 -12
  2. src/config/parser_models.rs +23 -0
src/config/parser.rs CHANGED
@@ -3,7 +3,7 @@
3
 
4
  use crate::handler::paths::{file_path, FileType};
5
 
6
- use super::parser_models::Style;
7
  use log::LevelFilter;
8
  use rlua::Lua;
9
  use std::{collections::HashMap, fs, thread::available_parallelism};
@@ -35,17 +35,7 @@ pub struct Config {
35
  pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
36
  pub request_timeout: u8,
37
  pub threads: u8,
38
- }
39
-
40
- /// Configuration options for the aggregator.
41
- ///
42
- /// # Fields
43
- ///
44
- /// * `random_delay` - It stores the option to whether enable or disable random delays between
45
- /// requests.
46
- #[derive(Clone)]
47
- pub struct AggregatorConfig {
48
- pub random_delay: bool,
49
  }
50
 
51
  impl Config {
@@ -88,6 +78,8 @@ impl Config {
88
  parsed_threads
89
  };
90
 
 
 
91
  Ok(Config {
92
  port: globals.get::<_, u16>("port")?,
93
  binding_ip: globals.get::<_, String>("binding_ip")?,
@@ -109,6 +101,10 @@ impl Config {
109
  .collect(),
110
  request_timeout: globals.get::<_, u8>("request_timeout")?,
111
  threads,
 
 
 
 
112
  })
113
  })
114
  }
 
3
 
4
  use crate::handler::paths::{file_path, FileType};
5
 
6
+ use super::parser_models::{AggregatorConfig, RateLimiter, Style};
7
  use log::LevelFilter;
8
  use rlua::Lua;
9
  use std::{collections::HashMap, fs, thread::available_parallelism};
 
35
  pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
36
  pub request_timeout: u8,
37
  pub threads: u8,
38
+ pub rate_limter: RateLimiter,
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
  impl Config {
 
78
  parsed_threads
79
  };
80
 
81
+ let rate_limter = globals.get::<_,HashMap<String, u8>>("rate_limiter")?;
82
+
83
  Ok(Config {
84
  port: globals.get::<_, u16>("port")?,
85
  binding_ip: globals.get::<_, String>("binding_ip")?,
 
101
  .collect(),
102
  request_timeout: globals.get::<_, u8>("request_timeout")?,
103
  threads,
104
+ rate_limter: RateLimiter {
105
+ number_of_requests: rate_limter["number_of_requests"],
106
+ time_limit: rate_limter["time_limit"],
107
+ }
108
  })
109
  })
110
  }
src/config/parser_models.rs CHANGED
@@ -36,3 +36,26 @@ impl Style {
36
  Style { theme, colorscheme }
37
  }
38
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  Style { theme, colorscheme }
37
  }
38
  }
39
+
40
+ /// Configuration options for the aggregator.
41
+ ///
42
+ /// # Fields
43
+ ///
44
+ /// * `random_delay` - It stores the option to whether enable or disable random delays between
45
+ /// requests.
46
+ #[derive(Clone)]
47
+ pub struct AggregatorConfig {
48
+ pub random_delay: bool,
49
+ }
50
+
51
+ /// Configuration options for the rate limter middleware.
52
+ ///
53
+ /// # Fields
54
+ ///
55
+ /// * `number_of_requests` -
56
+ /// * `time_limit` -
57
+ #[derive(Clone)]
58
+ pub struct RateLimiter {
59
+ pub number_of_requests: u8,
60
+ pub time_limit: u8,
61
+ }