neon_arch commited on
Commit
37e650e
1 Parent(s): d6463f0

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

Browse files
Files changed (1) hide show
  1. src/config/parser.rs +12 -0
src/config/parser.rs CHANGED
@@ -35,6 +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.
@@ -88,6 +89,16 @@ 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 +120,7 @@ impl Config {
109
  .collect(),
110
  request_timeout: globals.get::<_, u8>("request_timeout")?,
111
  threads,
 
112
  })
113
  })
114
  }
 
35
  pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
36
  pub request_timeout: u8,
37
  pub threads: u8,
38
+ pub safe_search: u8,
39
  }
40
 
41
  /// Configuration options for the aggregator.
 
89
  parsed_threads
90
  };
91
 
92
+ let parsed_safe_search:u8 = globals.get::<_,u8>("safe_search")?;
93
+ let safe_search: u8 = match parsed_safe_search {
94
+ 0..=4 => parsed_safe_search,
95
+ _ => {
96
+ log::error!("Config Error: The value of `safe_search` option should be a non zero positive integer from 0 to 4.");
97
+ log::error!("Falling back to using the value `1` for the option");
98
+ 1
99
+ }
100
+ };
101
+
102
  Ok(Config {
103
  port: globals.get::<_, u16>("port")?,
104
  binding_ip: globals.get::<_, String>("binding_ip")?,
 
120
  .collect(),
121
  request_timeout: globals.get::<_, u8>("request_timeout")?,
122
  threads,
123
+ safe_search
124
  })
125
  })
126
  }